Skip to content

Commit

Permalink
Update go and golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Ayers <[email protected]>
  • Loading branch information
smaye81 committed Sep 3, 2024
1 parent 9f0587c commit 1a7525e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ permissions:
jobs:
testlint:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.21.x, 1.22.x, 1.23.x]
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup-go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: ${{ matrix.go-version }}
- name: make-test
run: make test && make checkgenerate
- name: make-lint
# Often, lint & gofmt guidelines depend on the Go version. To prevent
# conflicting guidance, run only on the most recent supported version.
# For the same reason, only check generated code on the most recent
# supported version.
if: matrix.go-version == '1.23.x'
run: make lint
docker-build-push:
if: github.ref == 'refs/heads/main'
Expand Down
22 changes: 8 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
run:
skip-dirs-use-default: false
linters-settings:
errcheck:
check-type-assertions: true
Expand Down Expand Up @@ -32,37 +30,33 @@ linters-settings:
linters:
enable-all: true
disable:
- copyloopvar # only valid for go v1.22 and above
- cyclop # covered by gocyclo
- deadcode # abandoned
- depguard # in golangci-lint v1.53.0+ default requires only stdlib deps
- exhaustivestruct # replaced by exhaustruct
- exportloopref # deprecated in golangci v1.60.2
- execinquery # deprecated in golangci v1.58
- funlen # rely on code review to limit function length
- gocognit # dubious "cognitive overhead" quantification
- gofumpt # prefer standard gofmt
- goimports # rely on gci instead
- golint # deprecated by Go team
- gomnd # some unnamed constants are okay
- ifshort # deprecated by author
- interfacer # deprecated by author
- gomnd # deprecated in golangci v1.58 in favor of mnd
- mnd # some unnamed constants are okay
- intrange # only valid for go v1.22 and above
- ireturn # "accept interfaces, return structs" isn't ironclad
- lll # don't want hard limits for line length
- maintidx # covered by gocyclo
- maligned # readability trumps efficient struct packing
- nlreturn # generous whitespace violates house style
- nosnakecase # deprecated in https://github.com/golangci/golangci-lint/pull/3065
- paralleltest # in this project, it's not worth making all tests parallel
- scopelint # deprecated by author
- structcheck # abandoned
- testpackage # internal tests are fine
- tparallel # in this project, it's not worth making all tests parallel
- varcheck # abandoned
- wrapcheck # don't _always_ need to wrap errors
- wsl # generous whitespace violates house style
issues:
exclude-dirs-use-default: false
exclude:
# Don't ban use of fmt.Errorf to create new errors, but the remaining
# checks from err113 are useful.
- "err113: do not define dynamic errors.*"
- "do not define dynamic errors.*"
exclude-rules:
# It's much more convenient to keep eliza's matching and response data as
# globals rather than config.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $(BIN)/license-header: Makefile

$(BIN)/golangci-lint: Makefile
@mkdir -p $(@D)
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3

$(BIN)/protoc-gen-go: Makefile
@mkdir -p $(@D)
Expand Down
8 changes: 4 additions & 4 deletions cmd/demoserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (e *elizaServer) Say(
_ context.Context,
req *connect.Request[elizav1.SayRequest],
) (*connect.Response[elizav1.SayResponse], error) {
reply, _ := eliza.Reply(req.Msg.Sentence) // ignore end-of-conversation detection
reply, _ := eliza.Reply(req.Msg.GetSentence()) // ignore end-of-conversation detection
return connect.NewResponse(&elizav1.SayResponse{
Sentence: reply,
}), nil
Expand All @@ -73,7 +73,7 @@ func (e *elizaServer) Converse(
} else if err != nil {
return fmt.Errorf("receive request: %w", err)
}
reply, endSession := eliza.Reply(request.Sentence)
reply, endSession := eliza.Reply(request.GetSentence())
if err := stream.Send(&elizav1.ConverseResponse{Sentence: reply}); err != nil {
return fmt.Errorf("send response: %w", err)
}
Expand All @@ -88,7 +88,7 @@ func (e *elizaServer) Introduce(
req *connect.Request[elizav1.IntroduceRequest],
stream *connect.ServerStream[elizav1.IntroduceResponse],
) error {
name := req.Msg.Name
name := req.Msg.GetName()
if name == "" {
name = "Anonymous User"
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func newCORS() *cors.Cors {
http.MethodPatch,
http.MethodDelete,
},
AllowOriginFunc: func(origin string) bool {
AllowOriginFunc: func(_ /* origin */ string) bool {
// Allow all origins, which effectively disables CORS.
return true
},
Expand Down
39 changes: 25 additions & 14 deletions cmd/demoserver/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -59,8 +58,8 @@ func TestElizaServer(t *testing.T) {
result, err := client.Say(context.Background(), connect.NewRequest(&elizav1.SayRequest{
Sentence: "Hello",
}))
require.Nil(t, err)
assert.True(t, len(result.Msg.Sentence) > 0)
require.NoError(t, err)
assert.NotEmpty(t, result.Msg.GetSentence())
}
})
t.Run("converse", func(t *testing.T) {
Expand All @@ -70,13 +69,15 @@ func TestElizaServer(t *testing.T) {
stream := client.Converse(context.Background())
var wg sync.WaitGroup
wg.Add(2)
errs := make(chan error, 4)
go func() {
defer wg.Done()
for _, sentence := range sendValues {
err := stream.Send(&elizav1.ConverseRequest{Sentence: sentence})
require.Nil(t, err, fmt.Sprintf(`failed for string sentence: "%s"`, sentence))
errs <- err
}
require.Nil(t, stream.CloseRequest())
err := stream.CloseRequest()
errs <- err
}()
go func() {
defer wg.Done()
Expand All @@ -85,13 +86,23 @@ func TestElizaServer(t *testing.T) {
if errors.Is(err, io.EOF) {
break
}
require.Nil(t, err)
assert.True(t, len(msg.Sentence) > 0)
receivedValues = append(receivedValues, msg.Sentence)
errs <- err
assert.NotEmpty(t, msg.GetSentence())
receivedValues = append(receivedValues, msg.GetSentence())
}
require.Nil(t, stream.CloseResponse())
err := stream.CloseResponse()
errs <- err
}()
wg.Wait()
// close errs once all children finish.
go func() {
wg.Wait()
close(errs)
}()
for err := range errs {
if err != nil {
t.Fatal(err)
}
}
assert.Equal(t, len(receivedValues), len(sendValues))
}
})
Expand All @@ -102,13 +113,13 @@ func TestElizaServer(t *testing.T) {
Name: "Ringo",
})
stream, err := client.Introduce(context.Background(), request)
assert.Nil(t, err)
require.NoError(t, err)
for stream.Receive() {
total++
}
assert.Nil(t, stream.Err())
assert.Nil(t, stream.Close())
assert.True(t, total > 0)
assert.NoError(t, stream.Err())
assert.NoError(t, stream.Close())
assert.Positive(t, total)
}
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Users should clone the repo to explore the examples.
module connect-examples-go

go 1.18
go 1.21

require (
connectrpc.com/connect v1.14.0
Expand Down

0 comments on commit 1a7525e

Please sign in to comment.