iris/_examples/file-server/embedding-files-into-app/main.go

42 lines
839 B
Go
Raw Normal View History

package main
import (
2022-09-19 00:15:38 +02:00
"embed"
"github.com/kataras/iris/v12"
)
2022-09-19 00:15:38 +02:00
//go:embed assets/*
var fs embed.FS
func newApp() *iris.Application {
app := iris.New()
app.Logger().SetLevel("debug")
2022-09-19 00:15:38 +02:00
app.HandleDir("/static", fs)
/*
Or if you need to cache them inside the memory (requires the assets folder
to be located near the executable program):
2020-08-21 19:48:41 +02:00
app.HandleDir("/static", iris.Dir("./assets"), iris.DirOptions{
IndexName: "index.html",
Cache: iris.DirCacheOptions{
Enable: true,
Encodings: []string{"gzip"},
CompressIgnore: iris.MatchImagesAssets,
CompressMinSize: 30 * iris.B,
},
})
*/
return app
}
func main() {
app := newApp()
2021-02-19 08:41:24 +01:00
// http://localhost:8080/static/css/main.css
// http://localhost:8080/static/js/main.js
// http://localhost:8080/static/favicon.ico
app.Listen(":8080")
}