Skip to content

Commit

Permalink
fix: enable gofumpt instead of gofmt linter in server
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 27, 2024
1 parent 2abb334 commit 69efe31
Show file tree
Hide file tree
Showing 61 changed files with 365 additions and 293 deletions.
3 changes: 1 addition & 2 deletions server/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (t *tokenJWT) info(ctx context.Context, token string, rev uint64) (*AuthInf
return t.key, nil
}
})

if err != nil {
t.lg.Warn(
"failed to parse a JWT token",
Expand Down Expand Up @@ -137,7 +136,7 @@ func newTokenProviderJWT(lg *zap.Logger, optMap map[string]string) (*tokenJWT, e
return nil, ErrInvalidAuthOpts
}

var keys = make([]string, 0, len(optMap))
keys := make([]string, 0, len(optMap))
for k := range optMap {
if !knownOptions[k] {
keys = append(keys, k)
Expand Down
2 changes: 1 addition & 1 deletion server/auth/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestJWTTokenWithMissingFields(t *testing.T) {
}

func TestJWTBad(t *testing.T) {
var badCases = map[string]map[string]string{
badCases := map[string]map[string]string{
"no options": {},
"invalid method": {
"sign-method": "invalid",
Expand Down
2 changes: 2 additions & 0 deletions server/auth/nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ func (t *tokenNop) genTokenPrefix() (string, error) { return "", nil }
func (t *tokenNop) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) {
return nil, false
}

func (t *tokenNop) assign(ctx context.Context, username string, revision uint64) (string, error) {
return "", ErrAuthFailed
}

func newTokenProviderNop() (*tokenNop, error) {
return &tokenNop{}, nil
}
6 changes: 2 additions & 4 deletions server/auth/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ var knownOptions = map[string]bool{
optTTL: true,
}

var (
// DefaultTTL will be used when a 'ttl' is not specified
DefaultTTL = 5 * time.Minute
)
// DefaultTTL will be used when a 'ttl' is not specified
var DefaultTTL = 5 * time.Minute

type jwtOptions struct {
SignMethod jwt.SigningMethod
Expand Down
3 changes: 2 additions & 1 deletion server/auth/range_perm_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func checkKeyInterval(
lg *zap.Logger,
cachedPerms *unifiedRangePermissions,
key, rangeEnd []byte,
permtyp authpb.Permission_Type) bool {
permtyp authpb.Permission_Type,
) bool {
if isOpenEnded(rangeEnd) {
rangeEnd = nil
// nil rangeEnd will be converetd to []byte{}, the largest element of BytesAffineComparable,
Expand Down
12 changes: 8 additions & 4 deletions server/auth/range_perm_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@ func TestRangePermission(t *testing.T) {
},
{
[]adt.Interval{adt.NewBytesAffineInterval([]byte("a"), []byte("d")), adt.NewBytesAffineInterval([]byte("a"), []byte("b")), adt.NewBytesAffineInterval([]byte("c"), []byte("f"))},
[]byte("a"), []byte{},
[]byte("a"),
[]byte{},
false,
},
{
[]adt.Interval{adt.NewBytesAffineInterval([]byte("a"), []byte{})},
[]byte("a"), []byte{},
[]byte("a"),
[]byte{},
true,
},
{
[]adt.Interval{adt.NewBytesAffineInterval([]byte{0x00}, []byte{})},
[]byte("a"), []byte{},
[]byte("a"),
[]byte{},
true,
},
{
[]adt.Interval{adt.NewBytesAffineInterval([]byte{0x00}, []byte{})},
[]byte{0x00}, []byte{},
[]byte{0x00},
[]byte{},
true,
},
}
Expand Down
5 changes: 3 additions & 2 deletions server/auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) {
return nil, nil
}

//TODO(mitake|hexfusion) review unifying key names
// TODO(mitake|hexfusion) review unifying key names
ts, ok := md[rpctypes.TokenFieldNameGRPC]
if !ok {
ts, ok = md[rpctypes.TokenFieldNameSwagger]
Expand Down Expand Up @@ -1120,7 +1120,8 @@ func NewTokenProvider(
lg *zap.Logger,
tokenOpts string,
indexWaiter func(uint64) <-chan struct{},
TokenTTL time.Duration) (TokenProvider, error) {
TokenTTL time.Duration,
) (TokenProvider, error) {
tokenType, typeSpecificOpts, err := decomposeOpts(lg, tokenOpts)
if err != nil {
return nil, ErrInvalidAuthOpts
Expand Down
5 changes: 1 addition & 4 deletions server/auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ func TestRoleGrantPermission(t *testing.T) {
Name: "role-test-1",
Perm: perm,
})

if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -704,7 +703,6 @@ func TestRootRoleGrantPermission(t *testing.T) {
Name: "root",
Perm: perm,
})

if err != nil {
t.Error(err)
}
Expand All @@ -714,7 +712,7 @@ func TestRootRoleGrantPermission(t *testing.T) {
t.Fatal(err)
}

//whatever grant permission to root, it always return root permission.
// whatever grant permission to root, it always return root permission.
expectPerm := &authpb.Permission{
PermType: authpb.READWRITE,
Key: []byte{},
Expand Down Expand Up @@ -742,7 +740,6 @@ func TestRoleRevokePermission(t *testing.T) {
Name: "role-test-1",
Perm: perm,
})

if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func (sctx *serveCtx) serve(
errHandler func(error),
grpcDialForRestGatewayBackends func(ctx context.Context) (*grpc.ClientConn, error),
splitHTTP bool,
gopts ...grpc.ServerOption) (err error) {
gopts ...grpc.ServerOption,
) (err error) {
logger := defaultLog.New(io.Discard, "etcdhttp", 0)
<-s.ReadyNotify()

Expand Down
12 changes: 5 additions & 7 deletions server/etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ var (
gatewayCA string
)

var (
rootCmd = &cobra.Command{
Use: "etcd",
Short: "etcd server",
SuggestFor: []string{"etcd"},
}
)
var rootCmd = &cobra.Command{
Use: "etcd",
Short: "etcd server",
SuggestFor: []string{"etcd"},
}

func init() {
rootCmd.AddCommand(newGatewayCommand())
Expand Down
1 change: 0 additions & 1 deletion server/etcdserver/api/etcdhttp/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ func TestLinearizableReadCheck(t *testing.T) {

func checkHTTPResponse(t *testing.T, ts *httptest.Server, url string, expectStatusCode int, inResult []string, notInResult []string) {
res, err := ts.Client().Do(&http.Request{Method: http.MethodGet, URL: testutil.MustNewURL(t, ts.URL+url)})

if err != nil {
t.Fatalf("fail serve http request %s %v", url, err)
}
Expand Down
3 changes: 3 additions & 0 deletions server/etcdserver/api/etcdhttp/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ type fakeServer struct {
func (s *fakeServer) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) {
return nil, fmt.Errorf("AddMember not implemented in fakeServer")
}

func (s *fakeServer) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) {
return nil, fmt.Errorf("RemoveMember not implemented in fakeServer")
}

func (s *fakeServer) UpdateMember(ctx context.Context, updateMemb membership.Member) ([]*membership.Member, error) {
return nil, fmt.Errorf("UpdateMember not implemented in fakeServer")
}

func (s *fakeServer) PromoteMember(ctx context.Context, id uint64) ([]*membership.Member, error) {
return nil, fmt.Errorf("PromoteMember not implemented in fakeServer")
}
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func (c *RaftCluster) Store(store v2store.Store) {
)
}
for id := range c.removed {
//We do not need to delete the member since the store is empty.
// We do not need to delete the member since the store is empty.
mustAddToRemovedMembersInStore(c.lg, store, id)
}
if c.version != nil {
Expand Down
9 changes: 7 additions & 2 deletions server/etcdserver/api/membership/membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func TestAddRemoveMember(t *testing.T) {
c2 := newTestCluster(t, nil)
c2.SetBackend(be)
c2.Recover(func(*zap.Logger, *semver.Version) {})
assert.Equal(t, []*Member{{ID: types.ID(19),
Attributes: Attributes{Name: "node19"}}}, c2.Members())
assert.Equal(t, []*Member{{
ID: types.ID(19),
Attributes: Attributes{Name: "node19"},
}}, c2.Members())
assert.True(t, c2.IsIDRemoved(17))
assert.True(t, c2.IsIDRemoved(18))
assert.False(t, c2.IsIDRemoved(19))
Expand Down Expand Up @@ -78,14 +80,17 @@ func (b *backendMock) MustSaveClusterVersionToBackend(version *semver.Version) {
func (b *backendMock) MustReadMembersFromBackend() (x map[types.ID]*Member, y map[types.ID]bool) {
return b.members, b.removed
}

func (b *backendMock) MustSaveMemberToBackend(m *Member) {
b.members[m.ID] = m
}

func (b *backendMock) TrimMembershipFromBackend() error {
b.members = make(map[types.ID]*Member)
b.removed = make(map[types.ID]bool)
return nil
}

func (b *backendMock) MustDeleteMemberFromBackend(id types.ID) {
delete(b.members, id)
b.removed[id] = true
Expand Down
1 change: 1 addition & 0 deletions server/etcdserver/api/rafthttp/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ type respRoundTripper struct {
func newRespRoundTripper(code int, err error) *respRoundTripper {
return &respRoundTripper{code: code, err: err}
}

func (t *respRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
t.mu.Lock()
defer t.mu.Unlock()
Expand Down
6 changes: 2 additions & 4 deletions server/etcdserver/api/rafthttp/snapshot_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import (
"go.etcd.io/raft/v3"
)

var (
// timeout for reading snapshot response body
snapResponseReadTimeout = 5 * time.Second
)
// timeout for reading snapshot response body
var snapResponseReadTimeout = 5 * time.Second

type snapshotSender struct {
from, to types.ID
Expand Down
10 changes: 4 additions & 6 deletions server/etcdserver/api/rafthttp/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ func (t streamType) String() string {
}
}

var (
// linkHeartbeatMessage is a special message used as heartbeat message in
// link layer. It never conflicts with messages from raft because raft
// doesn't send out messages without From and To fields.
linkHeartbeatMessage = raftpb.Message{Type: raftpb.MsgHeartbeat}
)
// linkHeartbeatMessage is a special message used as heartbeat message in
// link layer. It never conflicts with messages from raft because raft
// doesn't send out messages without From and To fields.
var linkHeartbeatMessage = raftpb.Message{Type: raftpb.MsgHeartbeat}

func isLinkHeartbeatMessage(m *raftpb.Message) bool {
return m.Type == raftpb.MsgHeartbeat && m.From == 0 && m.To == 0
Expand Down
1 change: 1 addition & 0 deletions server/etcdserver/api/rafthttp/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (wrc *waitReadCloser) Read(p []byte) (int, error) {
<-wrc.closec
return 0, io.EOF
}

func (wrc *waitReadCloser) Close() error {
close(wrc.closec)
return nil
Expand Down
3 changes: 2 additions & 1 deletion server/etcdserver/api/rafthttp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func minClusterVersion(h http.Header) *semver.Version {
func checkVersionCompatibility(name string, server, minCluster *semver.Version) (
localServer *semver.Version,
localMinCluster *semver.Version,
err error) {
err error,
) {
localServer = semver.Must(semver.NewVersion(version.Version))
localMinCluster = semver.Must(semver.NewVersion(version.MinClusterVersion))
if compareMajorMinorVersion(server, localMinCluster) == -1 {
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/snap/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error {
spath := filepath.Join(s.dir, fname)

fsyncStart := time.Now()
err = pioutil.WriteAndSyncFile(spath, d, 0666)
err = pioutil.WriteAndSyncFile(spath, d, 0o666)
snapFsyncSec.Observe(time.Since(fsyncStart).Seconds())

if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions server/etcdserver/api/snap/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var testSnap = &raftpb.Snapshot{

func TestSaveAndLoad(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -65,7 +65,7 @@ func TestSaveAndLoad(t *testing.T) {

func TestBadCRC(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -88,14 +88,14 @@ func TestBadCRC(t *testing.T) {

func TestFailback(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

large := fmt.Sprintf("%016x-%016x-%016x.snap", 0xFFFF, 0xFFFF, 0xFFFF)
err = os.WriteFile(filepath.Join(dir, large), []byte("bad data"), 0666)
err = os.WriteFile(filepath.Join(dir, large), []byte("bad data"), 0o666)
if err != nil {
t.Fatal(err)
}
Expand All @@ -122,7 +122,7 @@ func TestFailback(t *testing.T) {

func TestSnapNames(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestSnapNames(t *testing.T) {

func TestLoadNewestSnap(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestLoadNewestSnap(t *testing.T) {

func TestNoSnapshot(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -229,7 +229,7 @@ func TestNoSnapshot(t *testing.T) {

func TestEmptySnapshot(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -250,7 +250,7 @@ func TestEmptySnapshot(t *testing.T) {
// ErrNoSnapshot if all the snapshots are broken.
func TestAllSnapshotBroken(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -270,7 +270,7 @@ func TestAllSnapshotBroken(t *testing.T) {

func TestReleaseSnapDBs(t *testing.T) {
dir := filepath.Join(os.TempDir(), "snapshot")
err := os.Mkdir(dir, 0700)
err := os.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand All @@ -279,7 +279,7 @@ func TestReleaseSnapDBs(t *testing.T) {
snapIndices := []uint64{100, 200, 300, 400}
for _, index := range snapIndices {
filename := filepath.Join(dir, fmt.Sprintf("%016x.snap.db", index))
if err := os.WriteFile(filename, []byte("snap file\n"), 0644); err != nil {
if err := os.WriteFile(filename, []byte("snap file\n"), 0o644); err != nil {
t.Fatal(err)
}
}
Expand Down
Loading

0 comments on commit 69efe31

Please sign in to comment.