xq ffd8e7ab59 embed | 1 year ago | |
---|---|---|
static | 1 year ago | |
.gitignore | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
conf.ini | 1 year ago | |
go.mod | 1 year ago | |
go.sum | 1 year ago | |
main.go | 1 year ago |
NAME:
webuploader - 文件服务
USAGE:
webuploader [global options] command [command options] [arguments...]
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--port value, -p value port (default: "8888")
--help, -h show help
GOOS=linux GOARCH=amd64 go build -o webup-linux-amd64 -a -ldflags '-w -s -extldflags "-static"' main.go
GOOS=linux GOARCH=arm64 go build -o webup-linux-arm64 -a -ldflags '-w -s -extldflags "-static"' main.go
GOOS=darwin GOARCH=amd64 go build -o webup-darwin-amd64 -a -ldflags '-w -s -extldflags "-static"' main.go
GOOS=darwin GOARCH=arm64 go build -o webup-darwin-arm64 -a -ldflags '-w -s -extldflags "-static"' main.go
GOOS=windows GOARCH=arm64 go build -o webup-windows-arm64.exe -a -ldflags '-w -s -extldflags "-static"' main.go
GOOS=windows GOARCH=amd64 go build -o webup-windows-amd64.exe -a -ldflags '-w -s -extldflags "-static"' main.go
go语言静态文件嵌入
;例子目录结构
# tree
├── main.go
└── static
├── fs.go
├── jquery-3.1.1.min.js
├── md5.js
└── upload.html
//例子文件 static/fs.go
package static
import (
"embed"
)
//go:embed *.css *.js *.html
var FS embed.FS
//例子文件 main.go
package main
import (
"net/http"
"webuploader/static" //本地文件夹 static
)
func main() {
fs := http.FileServer(http.FS(static.FS))
http.Handle("/path/", http.StripPrefix("/path/", fs))
http.ListenAndServe(":8080", nil)
}