From 9d99f227617b0b05ff2824223f016f9f874cc0ac Mon Sep 17 00:00:00 2001 From: yangxin Date: Thu, 14 Dec 2023 15:08:05 +0800 Subject: [PATCH 1/3] fix lint with "Cannot open: File exists" error --- .github/workflows/lint.yml | 26 ++++++++++++++----- Makefile | 2 +- .../pingchat/models/pingchat_chat_info.go | 9 ++++--- .../pingchat/models/pingchat_chat_message.go | 4 +-- .../pingchat/models/pingchat_chat_response.go | 2 +- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c7d9293d..e6cc188b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,9 +14,27 @@ on: - go.sum jobs: - golangci: + # https://github.com/golangci/golangci-lint-action/issues/23 + lint: name: lint runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.21 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3.3.0 + with: + version: v1.55.2 + + golangci: + name: golangci + runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v3 @@ -49,9 +67,3 @@ jobs: assert-nothing-changed go fmt ./... assert-nothing-changed go mod tidy exit $STATUS - - - - name: golangci-lint - uses: golangci/golangci-lint-action@v3.3.0 - with: - version: v1.52.2 diff --git a/Makefile b/Makefile index d0e5cc9d..f7e5cbe4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GOLANGCI_VERSION=v1.52.2 +GOLANGCI_VERSION=v1.55.2 COVERAGE=coverage.out .PHONY: deps diff --git a/pkg/tidbcloud/pingchat/models/pingchat_chat_info.go b/pkg/tidbcloud/pingchat/models/pingchat_chat_info.go index 8083e7bc..f3b97ccc 100644 --- a/pkg/tidbcloud/pingchat/models/pingchat_chat_info.go +++ b/pkg/tidbcloud/pingchat/models/pingchat_chat_info.go @@ -12,6 +12,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // PingchatChatInfo pingchat chat info @@ -19,7 +20,8 @@ import ( // swagger:model pingchat.ChatInfo type PingchatChatInfo struct { - // messages + // https://pkg.go.dev/gopkg.in/bluesuncorp/validator.v9#hdr-Dive + // Required: true Messages []*PingchatChatMessage `json:"messages"` } @@ -38,8 +40,9 @@ func (m *PingchatChatInfo) Validate(formats strfmt.Registry) error { } func (m *PingchatChatInfo) validateMessages(formats strfmt.Registry) error { - if swag.IsZero(m.Messages) { // not required - return nil + + if err := validate.Required("messages", "body", m.Messages); err != nil { + return err } for i := 0; i < len(m.Messages); i++ { diff --git a/pkg/tidbcloud/pingchat/models/pingchat_chat_message.go b/pkg/tidbcloud/pingchat/models/pingchat_chat_message.go index b8f95884..28acf2df 100644 --- a/pkg/tidbcloud/pingchat/models/pingchat_chat_message.go +++ b/pkg/tidbcloud/pingchat/models/pingchat_chat_message.go @@ -20,11 +20,11 @@ import ( // swagger:model pingchat.ChatMessage type PingchatChatMessage struct { - // content + // Dialogue content // Required: true Content *string `json:"content"` - // role + // User's input as "user", AI assistant's reply as "assistant" // Required: true // Enum: [user assistant] Role *string `json:"role"` diff --git a/pkg/tidbcloud/pingchat/models/pingchat_chat_response.go b/pkg/tidbcloud/pingchat/models/pingchat_chat_response.go index fb888358..7eac357e 100644 --- a/pkg/tidbcloud/pingchat/models/pingchat_chat_response.go +++ b/pkg/tidbcloud/pingchat/models/pingchat_chat_response.go @@ -22,7 +22,7 @@ type PingchatChatResponse struct { // content Content string `json:"content,omitempty"` - // links + // Reference Document Links Links []*PingchatLink `json:"links"` } From d6738c89facfcf851816fa238c8812ee144958ad Mon Sep 17 00:00:00 2001 From: yangxin Date: Thu, 14 Dec 2023 15:30:56 +0800 Subject: [PATCH 2/3] with golang file --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e6cc188b..3dd42188 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,7 +25,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.21 + go-version-file: './go.mod' - name: golangci-lint uses: golangci/golangci-lint-action@v3.3.0 @@ -42,7 +42,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.21 + go-version-file: './go.mod' - name: Restore Go modules cache uses: actions/cache@v3 From a2ee3b147c8104338524ff689f77faaeb2964862 Mon Sep 17 00:00:00 2001 From: yangxin Date: Thu, 14 Dec 2023 15:36:14 +0800 Subject: [PATCH 3/3] fmt --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3dd42188..feb17b30 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -32,8 +32,8 @@ jobs: with: version: v1.55.2 - golangci: - name: golangci + fmt: + name: fmt runs-on: ubuntu-latest steps: - name: Check out code