Skip to content

Commit

Permalink
Merge pull request #17624 from ivanvc/address-server-var-naming-lint-…
Browse files Browse the repository at this point in the history
…rule

server: address golangci var-naming issues
  • Loading branch information
ahrtr authored Mar 21, 2024
2 parents 3a9561a + 66f56d7 commit ef0c12f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 36 deletions.
20 changes: 10 additions & 10 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
}

for _, u := range cfg.ListenClientUrls {
addr, secure, network := resolveUrl(u)
addr, secure, network := resolveURL(u)
sctx := sctxs[addr]
if sctx == nil {
sctx = newServeCtx(cfg.logger)
Expand All @@ -652,7 +652,7 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
sctx.network = network
}
for _, u := range cfg.ListenClientHttpUrls {
addr, secure, network := resolveUrl(u)
addr, secure, network := resolveURL(u)

sctx := sctxs[addr]
if sctx == nil {
Expand Down Expand Up @@ -715,7 +715,7 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
return sctxs, nil
}

func resolveUrl(u url.URL) (addr string, secure bool, network string) {
func resolveURL(u url.URL) (addr string, secure bool, network string) {
addr = u.Host
network = "tcp"
if u.Scheme == "unix" || u.Scheme == "unixs" {
Expand Down Expand Up @@ -757,26 +757,26 @@ func (e *Etcd) serveClients() {
}))
}

splitHttp := false
splitHTTP := false
for _, sctx := range e.sctxs {
if sctx.httpOnly {
splitHttp = true
splitHTTP = true
}
}

// start client servers in each goroutine
for _, sctx := range e.sctxs {
go func(s *serveCtx) {
e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, mux, e.errHandler, e.grpcGatewayDial(splitHttp), splitHttp, gopts...))
e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, mux, e.errHandler, e.grpcGatewayDial(splitHTTP), splitHTTP, gopts...))
}(sctx)
}
}

func (e *Etcd) grpcGatewayDial(splitHttp bool) (grpcDial func(ctx context.Context) (*grpc.ClientConn, error)) {
func (e *Etcd) grpcGatewayDial(splitHTTP bool) (grpcDial func(ctx context.Context) (*grpc.ClientConn, error)) {
if !e.cfg.EnableGRPCGateway {
return nil
}
sctx := e.pickGrpcGatewayServeContext(splitHttp)
sctx := e.pickGRPCGatewayServeContext(splitHTTP)
addr := sctx.addr
if network := sctx.network; network == "unix" {
// explicitly define unix network for gRPC socket support
Expand Down Expand Up @@ -808,9 +808,9 @@ func (e *Etcd) grpcGatewayDial(splitHttp bool) (grpcDial func(ctx context.Contex
}
}

func (e *Etcd) pickGrpcGatewayServeContext(splitHttp bool) *serveCtx {
func (e *Etcd) pickGRPCGatewayServeContext(splitHTTP bool) *serveCtx {
for _, sctx := range e.sctxs {
if !splitHttp || !sctx.httpOnly {
if !splitHTTP || !sctx.httpOnly {
return sctx
}
}
Expand Down
16 changes: 8 additions & 8 deletions server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (sctx *serveCtx) serve(
handler http.Handler,
errHandler func(error),
grpcDialForRestGatewayBackends func(ctx context.Context) (*grpc.ClientConn, error),
splitHttp bool,
splitHTTP bool,
gopts ...grpc.ServerOption) (err error) {
logger := defaultLog.New(io.Discard, "etcdhttp", 0)
<-s.ReadyNotify()
Expand All @@ -105,9 +105,9 @@ func (sctx *serveCtx) serve(

m := cmux.New(sctx.l)
var server func() error
onlyGRPC := splitHttp && !sctx.httpOnly
onlyHttp := splitHttp && sctx.httpOnly
grpcEnabled := !onlyHttp
onlyGRPC := splitHTTP && !sctx.httpOnly
onlyHTTP := splitHTTP && sctx.httpOnly
grpcEnabled := !onlyHTTP
httpEnabled := !onlyGRPC

v3c := v3client.New(s)
Expand All @@ -129,7 +129,7 @@ func (sctx *serveCtx) serve(
switch {
case onlyGRPC:
traffic = "grpc"
case onlyHttp:
case onlyHTTP:
traffic = "http"
default:
traffic = "grpc+http"
Expand All @@ -144,7 +144,7 @@ func (sctx *serveCtx) serve(
Handler: createAccessController(sctx.lg, s, httpmux),
ErrorLog: logger, // do not log user error
}
if err = configureHttpServer(srv, s.Cfg); err != nil {
if err = configureHTTPServer(srv, s.Cfg); err != nil {
sctx.lg.Error("Configure http server failed", zap.Error(err))
return err
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (sctx *serveCtx) serve(
TLSConfig: tlscfg,
ErrorLog: logger, // do not log user error
}
if err := configureHttpServer(srv, s.Cfg); err != nil {
if err := configureHTTPServer(srv, s.Cfg); err != nil {
sctx.lg.Error("Configure https server failed", zap.Error(err))
return err
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func (sctx *serveCtx) serve(
return server()
}

func configureHttpServer(srv *http.Server, cfg config.ServerConfig) error {
func configureHTTPServer(srv *http.Server, cfg config.ServerConfig) error {
// todo (ahrtr): should we support configuring other parameters in the future as well?
return http2.ConfigureServer(srv, &http2.Server{
MaxConcurrentStreams: cfg.MaxConcurrentStreams,
Expand Down
4 changes: 4 additions & 0 deletions server/mock/mockstore/store_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ func (s *storeRecorder) Clone() v2store.Store {
return s
}

//revive:disable:var-naming
func (s *storeRecorder) JsonStats() []byte { return nil }

//revive:enable:var-naming

func (s *storeRecorder) DeleteExpiredKeys(cutoff time.Time) {
s.Record(testutil.Action{
Name: "DeleteExpiredKeys",
Expand Down
4 changes: 2 additions & 2 deletions server/storage/backend/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
ENV_VERIFY_VALUE_LOCK verify.VerificationType = "lock"
EnvVerifyValueLock verify.VerificationType = "lock"
)

func ValidateCalledInsideApply(lg *zap.Logger) {
Expand Down Expand Up @@ -57,7 +57,7 @@ func ValidateCalledInsideUnittest(lg *zap.Logger) {
}

func verifyLockEnabled() bool {
return verify.IsVerificationEnabled(ENV_VERIFY_VALUE_LOCK)
return verify.IsVerificationEnabled(EnvVerifyValueLock)
}

func insideApply() bool {
Expand Down
2 changes: 1 addition & 1 deletion server/storage/backend/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestLockVerify(t *testing.T) {
expectPanic: false,
},
}
revertVerifyFunc := verify.EnableVerifications(backend.ENV_VERIFY_VALUE_LOCK)
revertVerifyFunc := verify.EnableVerifications(backend.EnvVerifyValueLock)
defer revertVerifyFunc()
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions server/storage/schema/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func MustUnsafeGetAllLeases(tx backend.UnsafeReader) []*leasepb.Lease {
}

func MustUnsafePutLease(tx backend.UnsafeWriter, lpb *leasepb.Lease) {
key := leaseIdToBytes(lpb.ID)
key := leaseIDToBytes(lpb.ID)

val, err := lpb.Marshal()
if err != nil {
Expand All @@ -54,11 +54,11 @@ func MustUnsafePutLease(tx backend.UnsafeWriter, lpb *leasepb.Lease) {
}

func UnsafeDeleteLease(tx backend.UnsafeWriter, lpb *leasepb.Lease) {
tx.UnsafeDelete(Lease, leaseIdToBytes(lpb.ID))
tx.UnsafeDelete(Lease, leaseIDToBytes(lpb.ID))
}

func MustUnsafeGetLease(tx backend.UnsafeReader, leaseID int64) *leasepb.Lease {
_, vs := tx.UnsafeRange(Lease, leaseIdToBytes(leaseID), nil, 0)
_, vs := tx.UnsafeRange(Lease, leaseIDToBytes(leaseID), nil, 0)
if len(vs) != 1 {
return nil
}
Expand All @@ -70,7 +70,7 @@ func MustUnsafeGetLease(tx backend.UnsafeReader, leaseID int64) *leasepb.Lease {
return &lpb
}

func leaseIdToBytes(n int64) []byte {
func leaseIDToBytes(n int64) []byte {
bytes := make([]byte, 8)
binary.BigEndian.PutUint64(bytes, uint64(n))
return bytes
Expand Down
10 changes: 5 additions & 5 deletions server/storage/schema/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ func (s *membershipBackend) readMembersFromBackend() (map[types.ID]*membership.M
tx.RLock()
defer tx.RUnlock()
err := tx.UnsafeForEach(Members, func(k, v []byte) error {
memberId := mustParseMemberIDFromBytes(s.lg, k)
m := &membership.Member{ID: memberId}
memberID := mustParseMemberIDFromBytes(s.lg, k)
m := &membership.Member{ID: memberID}
if err := json.Unmarshal(v, &m); err != nil {
return err
}
members[memberId] = m
members[memberID] = m
return nil
})
if err != nil {
return nil, nil, fmt.Errorf("couldn't read members from backend: %v", err)
}

err = tx.UnsafeForEach(MembersRemoved, func(k, v []byte) error {
memberId := mustParseMemberIDFromBytes(s.lg, k)
removed[memberId] = true
memberID := mustParseMemberIDFromBytes(s.lg, k)
removed[memberID] = true
return nil
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/storage/wal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func readWALNames(lg *zap.Logger, dirpath string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("[readWALNames] fileutil.ReadDir failed: %w", err)
}
wnames := checkWalNames(lg, names)
wnames := checkWALNames(lg, names)
if len(wnames) == 0 {
return nil, ErrFileNotFound
}
return wnames, nil
}

func checkWalNames(lg *zap.Logger, names []string) []string {
func checkWALNames(lg *zap.Logger, names []string) []string {
wnames := make([]string, 0)
for _, name := range names {
if _, _, err := parseWALName(name); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions server/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.etcd.io/raft/v3/raftpb"
)

const ENV_VERIFY_VALUE_STORAGE_WAL verify.VerificationType = "storage_wal"
const envVerifyValueStorageWAL verify.VerificationType = "storage_wal"

type Config struct {
// DataDir is a root directory where the data being verified are stored.
Expand Down Expand Up @@ -77,7 +77,7 @@ func Verify(cfg Config) (retErr error) {
be := backend.NewDefaultBackend(lg, datadir.ToBackendFileName(cfg.DataDir))
defer be.Close()

snapshot, hardstate, err := validateWal(cfg)
snapshot, hardstate, err := validateWAL(cfg)
if err != nil {
return err
}
Expand All @@ -91,7 +91,7 @@ func Verify(cfg Config) (retErr error) {
// VerifyIfEnabled performs verification according to ETCD_VERIFY env settings.
// See Verify for more information.
func VerifyIfEnabled(cfg Config) error {
if verify.IsVerificationEnabled(ENV_VERIFY_VALUE_STORAGE_WAL) {
if verify.IsVerificationEnabled(envVerifyValueStorageWAL) {
return Verify(cfg)
}
return nil
Expand Down Expand Up @@ -131,7 +131,7 @@ func validateConsistentIndex(cfg Config, hardstate *raftpb.HardState, snapshot *
return nil
}

func validateWal(cfg Config) (*walpb.Snapshot, *raftpb.HardState, error) {
func validateWAL(cfg Config) (*walpb.Snapshot, *raftpb.HardState, error) {
walDir := datadir.ToWalDir(cfg.DataDir)

walSnaps, err := wal2.ValidSnapshotEntries(cfg.Logger, walDir)
Expand Down

0 comments on commit ef0c12f

Please sign in to comment.