From 3e671cfbef87cd311f39106a0f4522051fde8991 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:08:19 +0800 Subject: [PATCH 1/9] update goreleaser-action v6 --- .github/workflows/goreleaser-actions.yml | 7 +++---- .goreleaser.yaml | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/goreleaser-actions.yml b/.github/workflows/goreleaser-actions.yml index 4634eb1..044f47f 100644 --- a/.github/workflows/goreleaser-actions.yml +++ b/.github/workflows/goreleaser-actions.yml @@ -30,12 +30,11 @@ jobs: - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 #https://github.com/goreleaser/goreleaser-action with: distribution: goreleaser - # 'latest', 'nightly', or a semver - version: latest - args: release --snapshot --clean #--snapshot是不正式版本,取消git tag校验 + version: "~> v2" # or 'latest', 'nightly', semver + args: release --snapshot --clean #--snapshot是不正式版本,取消git tag校验 --clean清空dist目录 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c868e2a..9fb6909 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,7 +6,7 @@ # yaml-language-server: $schema=https://goreleaser.com/static/schema.json # vim: set ts=2 sw=2 tw=0 fo=cnqoj -version: 1 +version: 2 before: hooks: @@ -24,6 +24,7 @@ builds: - -X webdemo/appinfo.Tag={{ .Tag }} - -X webdemo/appinfo.Date={{ .Date }} - -X webdemo/appinfo.Commit={{ .FullCommit }} + - -X webdemo/appinfo.TreeState={{ .IsGitDirty }} # - -X main.Arch={{ .Arch }} # - -X main.Os={{ .Os }} # {{.名称模板}} https://goreleaser.com/customization/templates/#common-fields From 422a281d744c8d8da2bbf4e72f2b7ffc31285729 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:10:40 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BD=BF=E7=94=A8github.com/caarlos0/go-ve?= =?UTF-8?q?rsion=E8=BE=93=E5=87=BA-version=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appinfo/appinfo.go | 78 ++++++++++++++++++++++++++++++---------------- go.mod | 5 ++- webdemo.go | 5 +-- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/appinfo/appinfo.go b/appinfo/appinfo.go index 0f44393..77f8c36 100644 --- a/appinfo/appinfo.go +++ b/appinfo/appinfo.go @@ -1,35 +1,59 @@ -package webdemo +package appVersion import ( - "fmt" - "runtime" + goversion "github.com/caarlos0/go-version" ) var ( - BuiltBy string - Tag string - Commit string - Date string + BuiltBy string + Tag string + Commit string + Date string + TreeState string ) -type Info struct { - AppName string - AppVersion string - BuildTime string - GitHash string - // Pid int - Platform string - GoVersion string -} +// type infomation struct { +// AppName string +// AppVersion string +// BuildTime string +// GitHash string +// // Pid int +// Platform string +// GoVersion string +// } -var ( - AppInfo = Info{ - AppName: "简易文件服务器", - AppVersion: Tag, - BuildTime: Date, - GitHash: Commit, - // Pid: os.Getpid(), - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), - GoVersion: runtime.Version(), - } -) +// var ( +// AppInfo = infomation{ +// AppName: "简易文件服务器", +// AppVersion: Tag, +// BuildTime: Date, +// GitHash: Commit, +// // Pid: os.Getpid(), +// Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), +// GoVersion: runtime.Version(), +// } +// ) + +func BuildVersion() goversion.Info { + return goversion.GetVersionInfo( + goversion.WithAppDetails("简易文件http服务器", "局域网发送本地文件", "-h查询帮助"), + // goversion.WithASCIIName(asciiArt), + func(i *goversion.Info) { + if Commit != "" { + i.GitCommit = Commit + } + if TreeState != "" { + i.GitTreeState = TreeState + } + if Date != "" { + i.BuildDate = Date + } + if Tag != "" { + i.GitVersion = Tag + } + if BuiltBy != "" { + i.BuiltBy = BuiltBy + } + }, + ) +} diff --git a/go.mod b/go.mod index 67720df..b756dc4 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module webdemo go 1.21.6 -require github.com/quic-go/quic-go v0.46.0 +require ( + github.com/caarlos0/go-version v0.1.1 + github.com/quic-go/quic-go v0.46.0 +) require ( github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect diff --git a/webdemo.go b/webdemo.go index 04273c9..dd14ddc 100644 --- a/webdemo.go +++ b/webdemo.go @@ -9,7 +9,7 @@ import ( "net/http" "os" "strconv" - webdemo "webdemo/appinfo" + appVersion "webdemo/appinfo" "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/http3" @@ -151,7 +151,8 @@ func main() { flag.Parse() if showVersion { - fmt.Printf("%+v", webdemo.AppInfo) + // fmt.Printf("%+v\n", appVersion.AppInfo) + fmt.Println(appVersion.BuildVersion()) os.Exit(0) } From 6d240296e72a738531ebd21ee60393298c3a452d Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:46:38 +0800 Subject: [PATCH 3/9] =?UTF-8?q?update=20goreleaser=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/goreleaser-actions.yml | 2 +- .goreleaser.yaml | 52 +++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/.github/workflows/goreleaser-actions.yml b/.github/workflows/goreleaser-actions.yml index 044f47f..2fba270 100644 --- a/.github/workflows/goreleaser-actions.yml +++ b/.github/workflows/goreleaser-actions.yml @@ -34,7 +34,7 @@ jobs: with: distribution: goreleaser version: "~> v2" # or 'latest', 'nightly', semver - args: release --snapshot --clean #--snapshot是不正式版本,取消git tag校验 --clean清空dist目录 + args: release --clean #--snapshot 不正式版本,取消git tag校验 --clean清空dist目录 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9fb6909..7079edf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -15,16 +15,27 @@ before: # you may remove this if you don't need go generate # - go generate ./... +report_sizes: true + +gomod: + proxy: true +metadata: + mod_timestamp: "{{ .CommitTimestamp }}" + builds: - main: ./webdemo.go env: - - CGO_ENABLED=0 + - CGO_ENABLED=0 # 禁用 CGO + + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath # 优化二进制大小。 ldflags: - -s -w -X webdemo/appinfo.BuiltBy=goreleaser - -X webdemo/appinfo.Tag={{ .Tag }} - -X webdemo/appinfo.Date={{ .Date }} - -X webdemo/appinfo.Commit={{ .FullCommit }} - - -X webdemo/appinfo.TreeState={{ .IsGitDirty }} + - -X webdemo/appinfo.TreeState={{ .Branch }} # - -X main.Arch={{ .Arch }} # - -X main.Os={{ .Os }} # {{.名称模板}} https://goreleaser.com/customization/templates/#common-fields @@ -56,6 +67,9 @@ builds: - goos: windows goarch: mipsle +# universal_binaries: +# - replace: false # 禁用生成通用 macOS 二进制文件。 + upx: #压缩编译后的二进制文件大小 - # Whether to enable it or not. # @@ -109,3 +123,37 @@ changelog: exclude: - "^docs:" - "^test:" +checksum: + name_template: "checksums.txt" + # Algorithm to be used. + # + # Accepted options are: + # - sha256 + # - sha512 + # - sha1 + # - crc32 + # - md5 + # - sha224 + # - sha384 + # - sha3-256 + # - sha3-512 + # - sha3-224 + # - sha3-384 + # - blake2s + # - blake2b + # + # Default: 'sha256'. + algorithm: sha256 + + # If true, will create one checksum file for each artifact. + split: false + # IDs of artifacts to include in the checksums file. + # + # If left empty, all published binaries, archives, linux packages and source archives + # are included in the checksums file. + # ids: + # - foo + # - bar + + # Disable the generation/upload of the checksum file. + # disable: true \ No newline at end of file From 67909a0d9ea925ba2c896c64d8d443791baa61cb Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:48:22 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=BF=BD=E7=95=A5go.sum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cde0123..8dadee1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist/ +go.sum \ No newline at end of file From ee901921d9807c8051b1d8ed4ff2afcc95cc3e56 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:51:31 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=8F=96=E6=B6=88mod=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 7079edf..7dcecca 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -17,8 +17,8 @@ before: report_sizes: true -gomod: - proxy: true +# gomod: +# proxy: true metadata: mod_timestamp: "{{ .CommitTimestamp }}" From 7e3dea78a568e6879e17ac583ef308a6afd65e96 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:56:12 +0800 Subject: [PATCH 6/9] =?UTF-8?q?checksum=E6=94=BE=E5=88=B0archives=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yaml | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 7dcecca..5da1815 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -101,28 +101,8 @@ upx: #压缩编译后的二进制文件大小 # Whether to try all methods and filters (slow). brute: true -archives: - - format: tar.gz - # this name template makes the OS and Arch compatible with the results of `uname`. - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else if eq .Arch "arm64" }}aarch64 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - # use zip for windows archives - format_overrides: - - goos: windows - format: zip -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" + checksum: name_template: "checksums.txt" # Algorithm to be used. @@ -156,4 +136,27 @@ checksum: # - bar # Disable the generation/upload of the checksum file. - # disable: true \ No newline at end of file + # disable: true + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else if eq .Arch "arm64" }}aarch64 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" \ No newline at end of file From 13147592af7eadde3a72e13a7f2f61e736f50218 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:59:34 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5da1815..09b0cc7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -102,7 +102,8 @@ upx: #压缩编译后的二进制文件大小 brute: true - +signs: + - artifacts: checksum checksum: name_template: "checksums.txt" # Algorithm to be used. @@ -137,7 +138,8 @@ checksum: # Disable the generation/upload of the checksum file. # disable: true - +snapshot: + name_template: "{{ .Tag }}-next" archives: - format: tar.gz # this name template makes the OS and Arch compatible with the results of `uname`. From bc40376d7b29c7d37e531e7c3f798883bbe01824 Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:11:34 +0800 Subject: [PATCH 8/9] =?UTF-8?q?goreleaser=E9=85=8D=E7=BD=AEsnapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 09b0cc7..42dad7d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -139,7 +139,7 @@ checksum: # Disable the generation/upload of the checksum file. # disable: true snapshot: - name_template: "{{ .Tag }}-next" + version_template: "{{ .Version }}-SNAPSHOT-{{.ShortCommit}}" archives: - format: tar.gz # this name template makes the OS and Arch compatible with the results of `uname`. From d28cb843dc7609eb46f8ccefaa9456b51ba5826f Mon Sep 17 00:00:00 2001 From: WLaoDuo <69497874+WLaoDuo@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:31:24 +0800 Subject: [PATCH 9/9] =?UTF-8?q?update=20=09=09log.Println("=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=20\033[33m"=20+=20*path=5Fshow=20+?= =?UTF-8?q?=20"\033[0m")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webdemo.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webdemo.go b/webdemo.go index dd14ddc..f128258 100644 --- a/webdemo.go +++ b/webdemo.go @@ -46,7 +46,8 @@ func basicAuth(handler http.Handler, username, password, path string) http.Handl if !ok || user != username || pass != password { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) w.WriteHeader(http.StatusUnauthorized) - fmt.Fprintln(w, "Unauthorized") + fmt.Fprintln(w, "Unauthorized") //网页端认证失败返回文字 + log.Printf("\033[31m 非法访问者 %s \033[0m 使用%s 头,%s方式尝试请求文件\033[31m%s\033[0m", ip, ua, r.Method, path+r.URL.Path) return } else { @@ -173,8 +174,10 @@ func main() { cert, err_tls := tls.LoadX509KeyPair(*crtPath, *keyPath) + log.Println("文件路径 \033[33m" + *path_show + "\033[0m") + if err_tls == nil { - log.Println("文件路径 \033[33m" + *path_show + "\033[0m") + // log.Println("文件路径 \033[33m" + *path_show + "\033[0m") log.Printf("\033[33m%d\033[0m端口启用https", *port) _ = cert @@ -225,7 +228,6 @@ func main() { *port = 80 } log.Println(err_tls) - log.Println("文件路径未指定或文件路径不存在,默认为当前目录") log.Printf("找不到证书和私钥,\033[33m%d\033[0m端口启用http", *port) // http.Handle("/", authHandler) //当前目录