webuploader

xq ffd8e7ab59 embed преди 1 година
static b79e2e236b up преди 1 година
.gitignore d89ccb351d Initial commit преди 1 година
LICENSE d89ccb351d Initial commit преди 1 година
README.md ffd8e7ab59 embed преди 1 година
conf.ini b79e2e236b up преди 1 година
go.mod b79e2e236b up преди 1 година
go.sum b79e2e236b up преди 1 година
main.go a06e6f1072 ip преди 1 година

README.md

webuploader

  • Help
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

  • 最好保留6066端口 做为监控pprof
  • 编译
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)
}