static.LocalFile("./public",false)))// 其他路径 /other-place// r.Use(static.Serve("/other-place", static.LocalFile("./public", false)))r.GET("/ping",func(c*gin.Context){c.String(200,"test")})// Listen and Server in
router.Static("/assets","./assets") router.StaticFS("/more_static",http.Dir("my_file_system")) router.StaticFile("/favicon.ico","./resources/favicon.ico") // Listen and serve on 0.0.0.0:8080 router.Run(":8080") } 不过,这个例子中,官方只考虑到了静态资源都存放于二级目录,并且静态资源...
func main() { router := gin.Default() router.Static("/assets", "./assets") router.StaticFS("/more_static", http.Dir("my_file_system")) router.StaticFile("/favicon.ico", "./resources/favicon.ico") // Listen and serve on 0.0.0.0:8080 router.Run(":8080") } 1. 2. 3. 4. 5...
static和template目录是需要嵌入的目录; 因为main.go和static/template不在同一个目录,因此main.go中没法直接使用go:embed指令。我们在static的同级目录下创建一个文件:embed.go,专门用来写该指令。代码如下: packageembedexampleimport("embed")//go:embed staticvarStaticAsset embed.FS//go:embed templatevarTemplate...
//static server http.FileServer(http.Dir("目录")) //Manually configure the service and routing s := &http.Server{ Addr: ":8080", Handler: myHandler, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } s.ListenAndServe(); // path/filepath...
package mainimport("embed""log""net/http")// content holds the static content (2 files) for the web server.//go:embed a.txt b.txtvar content embed.FSfuncmain(){ http.Handle("/", http.FileServer(http.FS(content))) log.Fatal(http.ListenAndServe(":8080",nil))} 完整的Playgroun...
//static file handler. http.Handle("/staticfile/", http.StripPrefix("/staticfile/", http.FileServer(http.Dir("./staticfile"))) //Listen on port 8080 http.ListenAndServe(":8081", nil) } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10...
上面的代码首先是获取地址addr,然后执行fast-cgi,调用ListenAndServeTLS监听cgi服务,后面的是Http服务,调用ListenAndServe()监听http服务。 func ListenAndServe(addr string, handler Handler) error { server := &Server{Addr: addr, Handler: handler}returnserver.ListenAndServe() ...
https://github.com/thatsn0tmysite/xsserve https://github.com/EmYiQing/go-sqlmap https://github.com/EgeBalci/zippo https://github.com/drsigned/sigurlx https://github.com/drsigned/sigurls https://github.com/dowdyph0/transgo https://github.com/KathanP19/Gxss https://github.com/jweny/...
, "the directory to serve files from. Defaults to the current dir") flag.Parse() r := mux.NewRouter() // http://localhost:8000/static/<filename> r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(dir))) srv := &http.Server{ Handler: r, Addr...