Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.2 #4

Merged
merged 10 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/goreleaser-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 --clean #--snapshot 不正式版本,取消git tag校验 --clean清空dist目录
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

dist/
go.sum
62 changes: 58 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,15 +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={{ .Branch }}
# - -X main.Arch={{ .Arch }}
# - -X main.Os={{ .Os }}
# {{.名称模板}} https://goreleaser.com/customization/templates/#common-fields
Expand Down Expand Up @@ -55,6 +67,9 @@ builds:
- goos: windows
goarch: mipsle

# universal_binaries:
# - replace: false # 禁用生成通用 macOS 二进制文件。

upx: #压缩编译后的二进制文件大小
- # Whether to enable it or not.
#
Expand Down Expand Up @@ -86,6 +101,45 @@ upx: #压缩编译后的二进制文件大小
# Whether to try all methods and filters (slow).
brute: true


signs:
- artifacts: checksum
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
snapshot:
version_template: "{{ .Version }}-SNAPSHOT-{{.ShortCommit}}"
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
Expand All @@ -101,10 +155,10 @@ archives:
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^test:"
78 changes: 51 additions & 27 deletions appinfo/appinfo.go
Original file line number Diff line number Diff line change
@@ -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
}
},
)
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions webdemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -151,7 +152,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)
}

Expand All @@ -172,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

Expand Down Expand Up @@ -224,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) //当前目录
Expand Down
Loading