github.com/blend/go-sdk@v1.20220411.3/examples/web/static/main.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package main 9 10 import ( 11 "net/http" 12 13 "github.com/blend/go-sdk/graceful" 14 "github.com/blend/go-sdk/logger" 15 "github.com/blend/go-sdk/web" 16 ) 17 18 func main() { 19 log := logger.All() 20 app := web.MustNew(web.OptLog(log)) 21 csf := web.NewStaticFileServer( 22 web.OptStaticFileServerSearchPaths(http.Dir(".")), 23 ) 24 25 app.ServeStatic("/static/*filepath", []string{"_static"}) 26 app.ServeStaticCached("/static_cached/*filepath", []string{"_static"}) 27 app.GET("/", func(r *web.Ctx) web.Result { 28 return web.Static("index.html") 29 }) 30 app.GET("/cached", func(r *web.Ctx) web.Result { 31 return csf.ServeFile(r, "index.html") 32 }) 33 graceful.Shutdown(app) 34 }