Skip to content

embed.FS in golang 1.16beta1 #1755

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

Closed
aphsa opened this issue Jan 11, 2021 · 2 comments
Closed

embed.FS in golang 1.16beta1 #1755

aphsa opened this issue Jan 11, 2021 · 2 comments

Comments

@aphsa
Copy link

aphsa commented Jan 11, 2021

Is there any examples on how to embed static files to the golang binary using the new embed library for Golang 1.16.

golang/go@25d28ec

Currently I use the following methods in my code :

        e.Static("/", "public")
        e.File("/", "public/index.html")
@Bene-GG
Copy link

Bene-GG commented Jan 11, 2021

Found this working example: https://gist.github.com/wolfeidau/9f43e3f44cdb7a5f77405d3aa60421fc

@aphsa
Copy link
Author

aphsa commented Jan 13, 2021

Thank you. That worked! I am surprised how I didn't have to explicitly specify the index html.
Basically I have to change the code to the following.

        // content holds our static web server content.
        //go:embed public/*
        var content embed.FS

        var contentHandler = echo.WrapHandler(http.FileServer(http.FS(content)))
        var contentRewrite = middleware.Rewrite(map[string]string{"/*": "/public/$1"})

        e.GET("/*", contentHandler, contentRewrite)

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

No branches or pull requests

2 participants