diff --git a/.github/workflows/go-code-quality.yml b/.github/workflows/go-code-quality.yml index c987af4..9269ab3 100644 --- a/.github/workflows/go-code-quality.yml +++ b/.github/workflows/go-code-quality.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main # 或者你的默认分支 + - master jobs: build: @@ -17,11 +18,13 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.16' # 指定Go的版本 + go-version: '1.21' # 指定Go的版本 - name: Lint with golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v6 with: version: latest + github-token: ${{ secrets.GITHUB_TOKEN }} + # only-new-issues: true args: --issues-exit-code=0 --out-format=github-actions - + diff --git a/.gitignore b/.gitignore index ced6160..2ff78bf 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,4 @@ _cgo_export.* .vscode/* .DS_Store Thumbs.db +.history diff --git a/api/api.go b/api/api.go index a2934aa..6b7af68 100644 --- a/api/api.go +++ b/api/api.go @@ -5,7 +5,6 @@ import ( "net" "net/http" - "github.com/ckeyer/diego/api/view" "github.com/ckeyer/diego/pkgs/apis/ginmd" "github.com/ckeyer/diego/version" "github.com/gin-gonic/gin" @@ -18,6 +17,8 @@ const ( PrefixRelease = "release" // PrefixWebhook webhook PrefixWebhook = "webhook" + + Prefix_Api_Test = "test" ) // Serve start http server. @@ -29,7 +30,7 @@ func Serve(addr string) error { gs := gin.New() gs.Use(ginmd.MDCors()) - gs.NoRoute(view.UI()) + // gs.NoRoute(view.UI()) gs.Use(ginmd.MDRecovery(), ginmd.MDLogger()) apiRoute(gs.Group(PrefixAPI)) @@ -61,3 +62,7 @@ func getVersion(ctx *gin.Context) { func decodeBody(ctx *gin.Context, v interface{}) error { return json.NewDecoder(ctx.Request.Body).Decode(v) } + +func EncodeJSON(ctx *gin.Context, v interface{}) error { + return json.NewEncoder(ctx.Writer).Encode(v) +} diff --git a/api/users.go b/api/users.go index 2a3f174..db6d991 100644 --- a/api/users.go +++ b/api/users.go @@ -5,7 +5,6 @@ import ( "github.com/gin-gonic/gin" ) -// usersRouters ... func usersRouters(gr *gin.RouterGroup) { gr.GET("", users.ListUsers) gr.POST("", users.CreateUser) diff --git a/api/view/view.go b/api/view/view.go deleted file mode 100644 index 4671fc8..0000000 --- a/api/view/view.go +++ /dev/null @@ -1,51 +0,0 @@ -package view - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" -) - -var ( - Index, _ = Asset("index.html") -) - -func UI() gin.HandlerFunc { - return func(ctx *gin.Context) { - path := strings.TrimPrefix(ctx.Request.URL.Path, "/") - if path == "" { - path = "index.html" - } - - var ( - code = http.StatusOK - contentType = "text/html" - ) - // ctx.Writer.Header().Add("Content-Encoding", "gzip") - - switch { - case strings.HasSuffix(path, ".html"): - contentType = "text/html" - case strings.HasSuffix(path, ".js"): - contentType = "application/x-javascript" - case strings.HasSuffix(path, ".css"): - contentType = "text/css" - case strings.HasSuffix(path, ".svg"): - contentType = "text/xml" - case strings.HasSuffix(path, ".jpg"), strings.HasSuffix(path, ".jepg"): - contentType = "image/jpeg" - } - - body, err := Asset(path) - if err != nil { - logrus.Debugf("get path %s failed, use index.", path) - body = Index - } else { - logrus.Debugf("get path %s and return.", path) - } - - ctx.Data(code, contentType, body) - } -}