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

add embed example for go 1.16 #1175

Merged
merged 1 commit into from
Feb 18, 2021
Merged

add embed example for go 1.16 #1175

merged 1 commit into from
Feb 18, 2021

Conversation

circa10a
Copy link
Contributor

Go embedding was released in Go 1.16 yesterday. This PR is to add an example for how to use it with the filesystem middleware

@welcome
Copy link

welcome bot commented Feb 18, 2021

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@hi019
Copy link
Contributor

hi019 commented Feb 18, 2021

That was fast, thank you! Can we also put a notice about recommending this over the other solutions listed?

If your environment (Go 1.16+) supports it, we recommend using Go Embed instead of the other solutions listed as this one is native to Go and the easiest to use.

@circa10a
Copy link
Contributor Author

That was fast, thank you! Can we also put a notice about recommending this over the other solutions listed?

If your environment (Go 1.16+) supports it, we recommend using Go Embed instead of the other solutions listed as this one is native to Go and the easiest to use.

Added 👍

@hi019 hi019 merged commit 94995cf into gofiber:master Feb 18, 2021
@welcome
Copy link

welcome bot commented Feb 18, 2021

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@jorgefuertes
Copy link

Good idea, but seems needed to make an example to embed a static tree, not only one file, I'm stuck in that right now. Thanks!

@jorgefuertes
Copy link

jorgefuertes commented Feb 26, 2021

Please, note this in order to serve a directory tree:

//go:embed public
var public embed.FS

subFS, _ := fs.Sub(public, "public")
app.Use("/", filesystem.New(filesystem.Config{
	Root: http.FS(subFS),
}))

This was referenced Mar 15, 2021
@chiroro-jr
Copy link

Thank you so much for this merge. I was looking for something exactly like this to serve static assets from an embedded filesystem.

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 this pull request may close these issues.

None yet

4 participants