Skip to content

Commit

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

server/embed: address golangci var-naming issues
  • Loading branch information
ahrtr authored Apr 20, 2024
2 parents 0b7bae2 + 2e5188f commit 2674f94
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
57 changes: 30 additions & 27 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,15 @@ type Config struct {
// streams that each client can open at a time.
MaxConcurrentStreams uint32 `json:"max-concurrent-streams"`

//revive:disable:var-naming
ListenPeerUrls, ListenClientUrls, ListenClientHttpUrls []url.URL
AdvertisePeerUrls, AdvertiseClientUrls []url.URL
ClientTLSInfo transport.TLSInfo
ClientAutoTLS bool
PeerTLSInfo transport.TLSInfo
PeerAutoTLS bool
//revive:enable:var-naming

ClientTLSInfo transport.TLSInfo
ClientAutoTLS bool
PeerTLSInfo transport.TLSInfo
PeerAutoTLS bool
// SelfSignedCertValidity specifies the validity period of the client and peer certificates
// that are automatically generated by etcd when you specify ClientAutoTLS and PeerAutoTLS,
// the unit is year, and the default is 1
Expand Down Expand Up @@ -449,11 +452,11 @@ type configYAML struct {

// configJSON has file options that are translated into Config options
type configJSON struct {
ListenPeerUrls string `json:"listen-peer-urls"`
ListenClientUrls string `json:"listen-client-urls"`
ListenClientHttpUrls string `json:"listen-client-http-urls"`
AdvertisePeerUrls string `json:"initial-advertise-peer-urls"`
AdvertiseClientUrls string `json:"advertise-client-urls"`
ListenPeerURLs string `json:"listen-peer-urls"`
ListenClientURLs string `json:"listen-client-urls"`
ListenClientHTTPURLs string `json:"listen-client-http-urls"`
AdvertisePeerURLs string `json:"initial-advertise-peer-urls"`
AdvertiseClientURLs string `json:"advertise-client-urls"`

CORSJSON string `json:"cors"`
HostWhitelistJSON string `json:"host-whitelist"`
Expand Down Expand Up @@ -765,44 +768,44 @@ func (cfg *configYAML) configFromFile(path string) error {
return err
}

if cfg.configJSON.ListenPeerUrls != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenPeerUrls, ","))
if cfg.configJSON.ListenPeerURLs != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenPeerURLs, ","))
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-peer-urls: %v\n", err)
os.Exit(1)
}
cfg.Config.ListenPeerUrls = u
}

if cfg.configJSON.ListenClientUrls != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenClientUrls, ","))
if cfg.configJSON.ListenClientURLs != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenClientURLs, ","))
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-client-urls: %v\n", err)
os.Exit(1)
}
cfg.Config.ListenClientUrls = u
}

if cfg.configJSON.ListenClientHttpUrls != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenClientHttpUrls, ","))
if cfg.configJSON.ListenClientHTTPURLs != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.ListenClientHTTPURLs, ","))
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-client-http-urls: %v\n", err)
os.Exit(1)
}
cfg.Config.ListenClientHttpUrls = u
}

if cfg.configJSON.AdvertisePeerUrls != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.AdvertisePeerUrls, ","))
if cfg.configJSON.AdvertisePeerURLs != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.AdvertisePeerURLs, ","))
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error setting up initial-advertise-peer-urls: %v\n", err)
os.Exit(1)
}
cfg.Config.AdvertisePeerUrls = u
}

if cfg.configJSON.AdvertiseClientUrls != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.AdvertiseClientUrls, ","))
if cfg.configJSON.AdvertiseClientURLs != "" {
u, err := types.NewURLs(strings.Split(cfg.configJSON.AdvertiseClientURLs, ","))
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error setting up advertise-peer-urls: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -901,11 +904,11 @@ func (cfg *Config) Validate() error {
return err
}
if err := checkHostURLs(cfg.AdvertisePeerUrls); err != nil {
addrs := cfg.getAdvertisePeerUrls()
addrs := cfg.getAdvertisePeerURLs()
return fmt.Errorf(`--initial-advertise-peer-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err)
}
if err := checkHostURLs(cfg.AdvertiseClientUrls); err != nil {
addrs := cfg.getAdvertiseClientUrls()
addrs := cfg.getAdvertiseClientURLs()
return fmt.Errorf(`--advertise-client-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err)
}
// Check if conflicting flags are passed.
Expand Down Expand Up @@ -1104,7 +1107,7 @@ func (cfg *Config) GetDNSClusterNames() ([]string, error) {
zap.String("service-name", "etcd-server-ssl"+serviceNameSuffix),
zap.String("server-name", cfg.Name),
zap.String("discovery-srv", cfg.DNSCluster),
zap.Strings("advertise-peer-urls", cfg.getAdvertisePeerUrls()),
zap.Strings("advertise-peer-urls", cfg.getAdvertisePeerURLs()),
zap.Strings("found-cluster", clusterStrs),
zap.Error(cerr),
)
Expand All @@ -1119,7 +1122,7 @@ func (cfg *Config) GetDNSClusterNames() ([]string, error) {
zap.String("service-name", "etcd-server"+serviceNameSuffix),
zap.String("server-name", cfg.Name),
zap.String("discovery-srv", cfg.DNSCluster),
zap.Strings("advertise-peer-urls", cfg.getAdvertisePeerUrls()),
zap.Strings("advertise-peer-urls", cfg.getAdvertisePeerURLs()),
zap.Strings("found-cluster", clusterStrs),
zap.Error(httpCerr),
)
Expand Down Expand Up @@ -1275,31 +1278,31 @@ func checkHostURLs(urls []url.URL) error {
return nil
}

func (cfg *Config) getAdvertisePeerUrls() (ss []string) {
func (cfg *Config) getAdvertisePeerURLs() (ss []string) {
ss = make([]string, len(cfg.AdvertisePeerUrls))
for i := range cfg.AdvertisePeerUrls {
ss[i] = cfg.AdvertisePeerUrls[i].String()
}
return ss
}

func (cfg *Config) getListenPeerUrls() (ss []string) {
func (cfg *Config) getListenPeerURLs() (ss []string) {
ss = make([]string, len(cfg.ListenPeerUrls))
for i := range cfg.ListenPeerUrls {
ss[i] = cfg.ListenPeerUrls[i].String()
}
return ss
}

func (cfg *Config) getAdvertiseClientUrls() (ss []string) {
func (cfg *Config) getAdvertiseClientURLs() (ss []string) {
ss = make([]string, len(cfg.AdvertiseClientUrls))
for i := range cfg.AdvertiseClientUrls {
ss[i] = cfg.AdvertiseClientUrls[i].String()
}
return ss
}

func (cfg *Config) getListenClientUrls() (ss []string) {
func (cfg *Config) getListenClientURLs() (ss []string) {
ss = make([]string, len(cfg.ListenClientUrls))
for i := range cfg.ListenClientUrls {
ss[i] = cfg.ListenClientUrls[i].String()
Expand Down
24 changes: 12 additions & 12 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
}
e.cfg.logger.Info(
"configuring peer listeners",
zap.Strings("listen-peer-urls", e.cfg.getListenPeerUrls()),
zap.Strings("listen-peer-urls", e.cfg.getListenPeerURLs()),
)
if e.Peers, err = configurePeerListeners(cfg); err != nil {
return e, err
}

e.cfg.logger.Info(
"configuring client listeners",
zap.Strings("listen-client-urls", e.cfg.getListenClientUrls()),
zap.Strings("listen-client-urls", e.cfg.getListenClientURLs()),
)
if e.sctxs, err = configureClientListeners(cfg); err != nil {
return e, err
Expand Down Expand Up @@ -280,10 +280,10 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
e.cfg.logger.Info(
"now serving peer/client/metrics",
zap.String("local-member-id", e.Server.MemberID().String()),
zap.Strings("initial-advertise-peer-urls", e.cfg.getAdvertisePeerUrls()),
zap.Strings("listen-peer-urls", e.cfg.getListenPeerUrls()),
zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientUrls()),
zap.Strings("listen-client-urls", e.cfg.getListenClientUrls()),
zap.Strings("initial-advertise-peer-urls", e.cfg.getAdvertisePeerURLs()),
zap.Strings("listen-peer-urls", e.cfg.getListenPeerURLs()),
zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientURLs()),
zap.Strings("listen-client-urls", e.cfg.getListenClientURLs()),
zap.Strings("listen-metrics-urls", e.cfg.getMetricsURLs()),
)
serving = true
Expand Down Expand Up @@ -331,10 +331,10 @@ func print(lg *zap.Logger, ec Config, sc config.ServerConfig, memberInitialized
zap.Uint("max-wals", sc.MaxWALFiles),
zap.Uint("max-snapshots", sc.MaxSnapFiles),
zap.Uint64("snapshot-catchup-entries", sc.SnapshotCatchUpEntries),
zap.Strings("initial-advertise-peer-urls", ec.getAdvertisePeerUrls()),
zap.Strings("listen-peer-urls", ec.getListenPeerUrls()),
zap.Strings("advertise-client-urls", ec.getAdvertiseClientUrls()),
zap.Strings("listen-client-urls", ec.getListenClientUrls()),
zap.Strings("initial-advertise-peer-urls", ec.getAdvertisePeerURLs()),
zap.Strings("listen-peer-urls", ec.getListenPeerURLs()),
zap.Strings("advertise-client-urls", ec.getAdvertiseClientURLs()),
zap.Strings("listen-client-urls", ec.getListenClientURLs()),
zap.Strings("listen-metrics-urls", ec.getMetricsURLs()),
zap.Strings("cors", cors),
zap.Strings("host-whitelist", hss),
Expand Down Expand Up @@ -386,8 +386,8 @@ func (e *Etcd) Close() {
fields := []zap.Field{
zap.String("name", e.cfg.Name),
zap.String("data-dir", e.cfg.Dir),
zap.Strings("advertise-peer-urls", e.cfg.getAdvertisePeerUrls()),
zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientUrls()),
zap.Strings("advertise-peer-urls", e.cfg.getAdvertisePeerURLs()),
zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientURLs()),
}
lg := e.GetLogger()
lg.Info("closing etcd server", fields...)
Expand Down
8 changes: 4 additions & 4 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func TestConfigFileMemberFields(t *testing.T) {
Name string `json:"name"`
SnapshotCount uint64 `json:"snapshot-count"`
SnapshotCatchUpEntries uint64 `json:"experimental-snapshot-catch-up-entries"`
ListenPeerUrls string `json:"listen-peer-urls"`
ListenClientUrls string `json:"listen-client-urls"`
ListenClientHttpUrls string `json:"listen-client-http-urls"`
AdvertiseClientUrls string `json:"advertise-client-urls"`
ListenPeerURLs string `json:"listen-peer-urls"`
ListenClientURLs string `json:"listen-client-urls"`
ListenClientHTTPURLs string `json:"listen-client-http-urls"`
AdvertiseClientURLs string `json:"advertise-client-urls"`
}{
"testdir",
10,
Expand Down

0 comments on commit 2674f94

Please sign in to comment.