Skip to content

Implement standard fs.FS interface and friends  #169

@aol-nnov

Description

@aol-nnov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions