Skip to content

Commit

Permalink
Merge pull request #3 from WLaoDuo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
WLaoDuo authored Aug 21, 2024
2 parents b5ef397 + e89cd35 commit 470f226
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 53 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/goreleaser-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ name: goreleaser-actions
#https://github.com/goreleaser/goreleaser-action
#https://goreleaser.com/customization/builds/ 文档
on:
pull_request:
push:
branches:
- dev
tags:
- "v*"

permissions:
contents: read #write
# permissions:
# contents: read #write

jobs:
goreleaser-actions:
Expand All @@ -19,9 +20,14 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21.6'
- run: go version

-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
Expand All @@ -32,6 +38,20 @@ jobs:
args: release --snapshot --clean #--snapshot是不正式版本,取消git tag校验
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Github Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') #git push origin本地分支 release远程分支 v5.0版本号
with:
# prerelease: ${{ contains(env.GIT_TAG, 'rc') }}
# files: './dist/*'
files: |
./dist/*
./dist/simple_file_download_server[\w\.\-\_]+_checksums.txt
!./dist/[\w]+\.[json|yaml]+
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

-
name: Upload assets
uses: actions/upload-artifact@v4
Expand Down
25 changes: 14 additions & 11 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ builds:
- main: ./webdemo.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X webdemo/appinfo.BuiltBy=goreleaser
- -X webdemo/appinfo.Tag={{ .Tag }}
- -X webdemo/appinfo.Date={{ .Date }}
- -X webdemo/appinfo.Commit={{ .FullCommit }}
# - -X main.Arch={{ .Arch }}
# - -X main.Os={{ .Os }}
# {{.名称模板}} https://goreleaser.com/customization/templates/#common-fields

# gcflags:
# - all=-N -l
goos:
- linux
- windows
Expand Down Expand Up @@ -54,24 +65,16 @@ upx: #压缩编译后的二进制文件大小
# ids: [build1, build2]

# Filter by GOOS.
#
# Since: v1.19
goos: [windows]
goos: [linux]

# Filter by GOARCH.
#
# Since: v1.19
goarch: [amd64]
goarch: [mipsle]

# Filter by GOARM.
#
# Since: v1.19
# goarm: [8]

# Filter by GOAMD64.
#
# Since: v1.19
goamd64: [v1]
# goamd64: [v1]

# Compress argument.
# Valid options are from '1' (faster) to '9' (better), and 'best'.
Expand Down
35 changes: 35 additions & 0 deletions appinfo/appinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package webdemo

import (
"fmt"
"runtime"
)

var (
BuiltBy string
Tag string
Commit string
Date string
)

type Info 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(),
}
)
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module webdemo

go 1.21.6

require github.com/quic-go/quic-go v0.46.0

require (
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
Expand Down
38 changes: 0 additions & 38 deletions go.sum

This file was deleted.

9 changes: 9 additions & 0 deletions webdemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"strconv"
webdemo "webdemo/appinfo"

"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
Expand Down Expand Up @@ -145,14 +146,22 @@ func main() {
flag.StringVar(&password, "p", "", "密码") //短参数-p
port := flag.Int("port", 443, "端口")
var path_show = flag.String("path", ".", "文件路径") //文件加载路径,绝对路径可以,相对路径也可以,但需要注意加引号
var showVersion bool
flag.BoolVar(&showVersion, "version", false, "-version输出版本信息")
flag.Parse()

if showVersion {
fmt.Printf("%+v", webdemo.AppInfo)
os.Exit(0)
}

// result1 := exit_path(*crtPath) //crt证书是否存在
// result2 := exit_path(*keyPath) //key密钥是否存在
if exit_path(*path_show) != 0 {
log.Println("\033[31m ", *path_show, "\033[0m当前文件(文件夹)路径不存在,请重新输入")
os.Exit(1)
}

fileServer := http.FileServer(http.Dir(*path_show))
authHandler := basicAuth(fileServer, *username, password, *path_show)

Expand Down

0 comments on commit 470f226

Please sign in to comment.