Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement standard fs.FS interface and friends #169

Open
aol-nnov opened this issue Feb 11, 2023 · 3 comments
Open

Implement standard fs.FS interface and friends #169

aol-nnov opened this issue Feb 11, 2023 · 3 comments

Comments

@aol-nnov
Copy link
Contributor

I've stumbled upon this interesting package during my research on how to serve contents of iso file over http.

Definitely, I could loop-mount it and just serve static files from mount point, but the idea of implementing it completely in go took me over.

So, my web part is implemented using gin-gonik and it has a very handy FileFromFS method, that operates through standard io.FS interface.

I'm quite a new gopher and do not have enough knowlegde to improve such a big go projects, so I've started with a wrapper around go-diskfs. It, actually work, but, it's very much suboptimal in many ways as it does not have access to the internals of this project.

If this would be implemented, the actual code of serving files from iso will boil down to the following:

func main() {
        app := gin.Default()
	
	disk, err := diskfs.Open("/path/to/image.iso")
	if err != nil {
		log.Fatalf("failed to open file: %s", err)
	}
	
	isofs, err := disk.GetFilesystem(0)

	if err != nil {
		log.Fatalf("failed to get partition 0: %s", err)
	}
	
	app.GET("/iso/*path", func(c *gin.Context) {
		c.FileFromFS(c.Param("path"), http.FS(isofs))
	})
	
	a.Run(":8080")
}

Any help will be appreciated!

If you're interested in the idea behind this - it's quite trivial: to serve linux distribution repos from the iso file over http for group access.

@deitch
Copy link
Collaborator

deitch commented Feb 12, 2023

but, it's very much suboptimal in many ways

I don't see how it is suboptimal. It is simple and straightforward, and serves the files. Does it work? Or do you need an fs.FS interface provided?

@aol-nnov
Copy link
Contributor Author

Sorry for being unclear, @deitch At some point of digging different sources it seemed to me that io.FS is an alias to fs.FS..

So, yes, it is fs.FS that is needed to be provided.

I don't see how it is suboptimal.

Again, to clarify a bit: my implementation appeared suboptimal as it is mostly a wrapper around go-diskfs providing missing methods. And as some structures (directoryEntry, for example) are not exported from go-diskfs, I had to reinvent the wheel in my wrapper..

@deitch
Copy link
Collaborator

deitch commented Feb 14, 2023

I like the idea of providing an fs.FS interface.

@aol-nnov aol-nnov changed the title Implement standard io.FS interface and friends Implement standard fs.FS interface and friends Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants