From 9f25a90ae5223810f8d7d8267274e31b2735e749 Mon Sep 17 00:00:00 2001 From: huoxue1 <3343780376@qq.com> Date: Tue, 5 Sep 2023 19:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 47 ++++++++++++++ .../workflows/push-to-docker.yml | 0 {.github => .gitea}/workflows/release.yml | 0 .github/workflows/ci.yml | 64 ------------------- .goreleaser.yml | 51 ++------------- api/server/server.go | 20 ++++-- utils/run.go | 4 +- 7 files changed, 69 insertions(+), 117 deletions(-) create mode 100644 .gitea/workflows/ci.yml rename {.github => .gitea}/workflows/push-to-docker.yml (100%) rename {.github => .gitea}/workflows/release.yml (100%) delete mode 100644 .github/workflows/ci.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..2f4934a --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,47 @@ +name: CI + +on: [push, pull_request] + +env: + BINARY_PREFIX: "qinglong-go_" + BINARY_SUFFIX: "" + COMMIT_ID: "${{ github.sha }}" + PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." + LD_FLAGS: "-w -s" + VERSION: "action" + HTTP_PROXY: "http://172.17.0.1:7890" + HTTPS_PROXY: "http://172.17.0.1:7890" + GOPROXY: "https://goproxy.cn,direct" + +jobs: + build: + name: Build binary CI + runs-on: ubuntu-latest + container: + image: node:16-bullseye + # 持久化工具目录 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: setup go + uses: https://github.com/actions/setup-go@v4 + with: + go-version: '1.20' + - name: Fetch all tags + run: git fetch --force --tags + - name: Run GoReleaser + uses: https://huoxue.link:12300/huoxue1/goreleaser-action@master + with: + version: latest + args: build --snapshot + env: + GITEA_TOKEN: ${{ secrets.TOKEN }} +# - name: upload-artifact +# uses: actions/upload-artifact@v3 +# with: +# name: my-artifact +# path: dist/*/* + + diff --git a/.github/workflows/push-to-docker.yml b/.gitea/workflows/push-to-docker.yml similarity index 100% rename from .github/workflows/push-to-docker.yml rename to .gitea/workflows/push-to-docker.yml diff --git a/.github/workflows/release.yml b/.gitea/workflows/release.yml similarity index 100% rename from .github/workflows/release.yml rename to .gitea/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 2fdb824..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: CI - -on: [push, pull_request] - -env: - BINARY_PREFIX: "qinglong-go_" - BINARY_SUFFIX: "" - COMMIT_ID: "${{ github.sha }}" - PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." - LD_FLAGS: "-w -s" - VERSION: "action" - -jobs: - build: - name: Build binary CI - runs-on: ubuntu-latest - strategy: - matrix: - # build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 - goos: [linux, windows, darwin] - goarch: ["386", amd64, arm, arm64] - exclude: - - goos: darwin - goarch: arm - - goos: darwin - goarch: "386" - - goos: windows - goarch: arm64 - - goos: windows - goarch: arm - fail-fast: true - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Fetch all tags - run: git fetch --force --tags - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: "1.20" - - - name: Build binary file - env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - IS_PR: ${{ !!github.head_ref }} - CGO_ENABLED: 0 - run: | - if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi - if $IS_PR ; then echo $PR_PROMPT; fi - export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX" - export LD_FLAGS="-w -s -X github.com/huoxue1/qinglong-go/service/config.VERSION=${VERSION}" - go mod tidy - go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" ./ - - name: Upload artifact - uses: actions/upload-artifact@v2 - if: ${{ !github.head_ref }} - with: - name: ${{ matrix.goos }}_${{ matrix.goarch }} - path: output/ - - diff --git a/.goreleaser.yml b/.goreleaser.yml index c9f7ea8..d6961f4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,21 +11,9 @@ builds: - GO111MODULE=on goos: - linux - - darwin goarch: - - 386 - amd64 - - arm - arm64 - goarm: - - 7 - ignore: - - goos: darwin - goarch: arm - - goos: darwin - goarch: 386 - - goos: windows - goarch: arm mod_timestamp: "{{ .CommitTimestamp }}" flags: - -trimpath @@ -38,34 +26,12 @@ builds: goos: - windows goarch: - - 386 - amd64 - goarm: - - 7 mod_timestamp: "{{ .CommitTimestamp }}" flags: - -trimpath ldflags: - -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}} - - id: docker - env: - - CGO_ENABLED=0 - - GO111MODULE=on - goos: - - linux - goarch: - - 386 - - amd64 - - arm - - arm64 - goarm: - - 7 - mod_timestamp: "{{ .CommitTimestamp }}" - flags: - - -trimpath - ldflags: - - -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}} - checksum: name_template: "{{ .ProjectName }}_checksums.txt" changelog: @@ -97,14 +63,9 @@ archives: - goos: windows format: zip -nfpms: - - license: AGPL 3.0 - homepage: https://github.com/johlanse/study_xxqg - file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" - formats: - - deb - - rpm - maintainer: johlanse - builds: - - nowin - - win \ No newline at end of file +release: + gitea: + owner: "huoxue1" + name: "qinglong-go" + name_template: "{{.ProjectName}}-v{{.Version}} {{.Env.USER}}" + disable: false \ No newline at end of file diff --git a/api/server/server.go b/api/server/server.go index af35a31..c3b2615 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -14,20 +14,28 @@ func Api(group *gin.RouterGroup) { http.MethodDelete, http.MethodPut, http.MethodOptions, - }, "/:path", handle()) + }, "/:path", handle(false)) + + group.Match([]string{ + http.MethodGet, + http.MethodPost, + http.MethodDelete, + http.MethodPut, + http.MethodOptions, + }, "/log/:path", handle(true)) } -func handle() gin.HandlerFunc { +func handle(logEnable bool) gin.HandlerFunc { return func(ctx *gin.Context) { path := ctx.Param("path") query := make(map[string]string) - ctx.ShouldBindQuery(&query) + _ = ctx.ShouldBindQuery(&query) headers := make(map[string]string) - ctx.ShouldBindHeader(&headers) + _ = ctx.ShouldBindHeader(&headers) body := make(map[string]any) - ctx.ShouldBind(&body) - data := server.Run(ctx, path, query, body, headers, false) + _ = ctx.ShouldBind(&body) + data := server.Run(ctx, path, query, body, headers, logEnable) ctx.Writer.WriteHeader(200) ctx.Writer.Header().Add("Content-Type", "application/json") _, _ = ctx.Writer.WriteString(data) diff --git a/utils/run.go b/utils/run.go index 3801d72..1babe58 100644 --- a/utils/run.go +++ b/utils/run.go @@ -97,8 +97,8 @@ func RunWithOption(ctx context.Context, option *RunOption) { ch <- 1 return } - go io.Copy(option.LogFile, stderrPipe) - go io.Copy(option.LogFile, stdoutPipe) + io.Copy(option.LogFile, stderrPipe) + io.Copy(option.LogFile, stdoutPipe) err = cmd.Wait() if err != nil { ch <- 1