Skip to content

Commit f36cffd

Browse files
authored
Merge branch 'main' into e2e-caching
2 parents 19c43d9 + 6b0e715 commit f36cffd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+409
-351
lines changed

.golangci.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ linters-settings:
8787
linters:
8888
enable-all: true
8989
disable:
90+
# deprecated:
9091
- gomnd
9192
- execinquery
93+
9294
- depguard
9395
- nlreturn
9496
- godox
@@ -101,23 +103,22 @@ linters:
101103
- wsl
102104
- wrapcheck
103105
- testpackage
104-
# TODO: I didn't manage to make it accept short parameter names
106+
# TODO: varnamelen: I didn't manage to make it accept short parameter names
105107
- varnamelen
106-
# TODO: consider enabling it later on
108+
# TODO: ireturn: consider enabling it later on
107109
- ireturn
108110
- godot
109111
presets: [ ]
110112
fast: false
111113

112114
issues:
113-
# Excluding configuration per-path, per-linter, per-text and per-source
115+
# Exclude certain checks in test files
114116
exclude-rules:
115-
- path: _test\.go
116-
linters:
117-
- gosec
118-
- path: cmd/soroban-rpc/internal/integrationtest/infrastructure/
117+
- path: '^(.*_test\.go|cmd/soroban-rpc/internal/integrationtest/infrastructure/.*)$'
119118
linters:
119+
- mnd
120120
- gosec
121-
121+
- gochecknoglobals
122+
- nosprintfhostport
122123
run:
123124
timeout: 10m
Lines changed: 72 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:forcetypeassert // this file uses several unchecked assertions
12
package config
23

34
import (
@@ -22,151 +23,153 @@ func (cfg *Config) AddFlags(cmd *cobra.Command) error {
2223
}
2324

2425
// AddFlag adds a CLI flag for this option to the given flagset.
25-
func (co *ConfigOption) AddFlag(flagset *pflag.FlagSet) error {
26+
//
27+
//nolint:funlen,cyclop
28+
func (o *Option) AddFlag(flagset *pflag.FlagSet) error {
2629
// config options that has no names do not represent a valid flag.
27-
if len(co.Name) == 0 {
30+
if len(o.Name) == 0 {
2831
return nil
2932
}
3033
// Treat any option with a custom parser as a string option.
31-
if co.CustomSetValue != nil {
32-
if co.DefaultValue == nil {
33-
co.DefaultValue = ""
34+
if o.CustomSetValue != nil {
35+
if o.DefaultValue == nil {
36+
o.DefaultValue = ""
3437
}
35-
flagset.String(co.Name, fmt.Sprint(co.DefaultValue), co.UsageText())
36-
co.flag = flagset.Lookup(co.Name)
38+
flagset.String(o.Name, fmt.Sprint(o.DefaultValue), o.UsageText())
39+
o.flag = flagset.Lookup(o.Name)
3740
return nil
3841
}
3942

4043
// Infer the type of the flag based on the type of the ConfigKey. This list
4144
// of options is based on the available flag types from pflags
42-
switch co.ConfigKey.(type) {
45+
switch o.ConfigKey.(type) {
4346
case *bool:
44-
flagset.Bool(co.Name, co.DefaultValue.(bool), co.UsageText())
47+
flagset.Bool(o.Name, o.DefaultValue.(bool), o.UsageText())
4548
case *time.Duration:
46-
flagset.Duration(co.Name, co.DefaultValue.(time.Duration), co.UsageText())
49+
flagset.Duration(o.Name, o.DefaultValue.(time.Duration), o.UsageText())
4750
case *float32:
48-
flagset.Float32(co.Name, co.DefaultValue.(float32), co.UsageText())
51+
flagset.Float32(o.Name, o.DefaultValue.(float32), o.UsageText())
4952
case *float64:
50-
flagset.Float64(co.Name, co.DefaultValue.(float64), co.UsageText())
53+
flagset.Float64(o.Name, o.DefaultValue.(float64), o.UsageText())
5154
case *net.IP:
52-
flagset.IP(co.Name, co.DefaultValue.(net.IP), co.UsageText())
55+
flagset.IP(o.Name, o.DefaultValue.(net.IP), o.UsageText())
5356
case *net.IPNet:
54-
flagset.IPNet(co.Name, co.DefaultValue.(net.IPNet), co.UsageText())
57+
flagset.IPNet(o.Name, o.DefaultValue.(net.IPNet), o.UsageText())
5558
case *int:
56-
flagset.Int(co.Name, co.DefaultValue.(int), co.UsageText())
59+
flagset.Int(o.Name, o.DefaultValue.(int), o.UsageText())
5760
case *int8:
58-
flagset.Int8(co.Name, co.DefaultValue.(int8), co.UsageText())
61+
flagset.Int8(o.Name, o.DefaultValue.(int8), o.UsageText())
5962
case *int16:
60-
flagset.Int16(co.Name, co.DefaultValue.(int16), co.UsageText())
63+
flagset.Int16(o.Name, o.DefaultValue.(int16), o.UsageText())
6164
case *int32:
62-
flagset.Int32(co.Name, co.DefaultValue.(int32), co.UsageText())
65+
flagset.Int32(o.Name, o.DefaultValue.(int32), o.UsageText())
6366
case *int64:
64-
flagset.Int64(co.Name, co.DefaultValue.(int64), co.UsageText())
67+
flagset.Int64(o.Name, o.DefaultValue.(int64), o.UsageText())
6568
case *[]int:
66-
flagset.IntSlice(co.Name, co.DefaultValue.([]int), co.UsageText())
69+
flagset.IntSlice(o.Name, o.DefaultValue.([]int), o.UsageText())
6770
case *[]int32:
68-
flagset.Int32Slice(co.Name, co.DefaultValue.([]int32), co.UsageText())
71+
flagset.Int32Slice(o.Name, o.DefaultValue.([]int32), o.UsageText())
6972
case *[]int64:
70-
flagset.Int64Slice(co.Name, co.DefaultValue.([]int64), co.UsageText())
73+
flagset.Int64Slice(o.Name, o.DefaultValue.([]int64), o.UsageText())
7174
case *string:
7275
// Set an empty string if no default was provided, since some value is always required for pflags
73-
if co.DefaultValue == nil {
74-
co.DefaultValue = ""
76+
if o.DefaultValue == nil {
77+
o.DefaultValue = ""
7578
}
76-
flagset.String(co.Name, co.DefaultValue.(string), co.UsageText())
79+
flagset.String(o.Name, o.DefaultValue.(string), o.UsageText())
7780
case *[]string:
7881
// Set an empty string if no default was provided, since some value is always required for pflags
79-
if co.DefaultValue == nil {
80-
co.DefaultValue = []string{}
82+
if o.DefaultValue == nil {
83+
o.DefaultValue = []string{}
8184
}
82-
flagset.StringSlice(co.Name, co.DefaultValue.([]string), co.UsageText())
85+
flagset.StringSlice(o.Name, o.DefaultValue.([]string), o.UsageText())
8386
case *uint:
84-
flagset.Uint(co.Name, co.DefaultValue.(uint), co.UsageText())
87+
flagset.Uint(o.Name, o.DefaultValue.(uint), o.UsageText())
8588
case *uint8:
86-
flagset.Uint8(co.Name, co.DefaultValue.(uint8), co.UsageText())
89+
flagset.Uint8(o.Name, o.DefaultValue.(uint8), o.UsageText())
8790
case *uint16:
88-
flagset.Uint16(co.Name, co.DefaultValue.(uint16), co.UsageText())
91+
flagset.Uint16(o.Name, o.DefaultValue.(uint16), o.UsageText())
8992
case *uint32:
90-
flagset.Uint32(co.Name, co.DefaultValue.(uint32), co.UsageText())
93+
flagset.Uint32(o.Name, o.DefaultValue.(uint32), o.UsageText())
9194
case *uint64:
92-
flagset.Uint64(co.Name, co.DefaultValue.(uint64), co.UsageText())
95+
flagset.Uint64(o.Name, o.DefaultValue.(uint64), o.UsageText())
9396
case *[]uint:
94-
flagset.UintSlice(co.Name, co.DefaultValue.([]uint), co.UsageText())
97+
flagset.UintSlice(o.Name, o.DefaultValue.([]uint), o.UsageText())
9598
default:
96-
return fmt.Errorf("unexpected option type: %T", co.ConfigKey)
99+
return fmt.Errorf("unexpected option type: %T", o.ConfigKey)
97100
}
98101

99-
co.flag = flagset.Lookup(co.Name)
102+
o.flag = flagset.Lookup(o.Name)
100103
return nil
101104
}
102105

103-
func (co *ConfigOption) GetFlag(flagset *pflag.FlagSet) (interface{}, error) {
106+
//nolint:cyclop
107+
func (o *Option) GetFlag(flagset *pflag.FlagSet) (interface{}, error) {
104108
// Treat any option with a custom parser as a string option.
105-
if co.CustomSetValue != nil {
106-
return flagset.GetString(co.Name)
109+
if o.CustomSetValue != nil {
110+
return flagset.GetString(o.Name)
107111
}
108112

109113
// Infer the type of the flag based on the type of the ConfigKey. This list
110114
// of options is based on the available flag types from pflags, and must
111115
// match the above in `AddFlag`.
112-
switch co.ConfigKey.(type) {
116+
switch o.ConfigKey.(type) {
113117
case *bool:
114-
return flagset.GetBool(co.Name)
118+
return flagset.GetBool(o.Name)
115119
case *time.Duration:
116-
return flagset.GetDuration(co.Name)
120+
return flagset.GetDuration(o.Name)
117121
case *float32:
118-
return flagset.GetFloat32(co.Name)
122+
return flagset.GetFloat32(o.Name)
119123
case *float64:
120-
return flagset.GetFloat64(co.Name)
124+
return flagset.GetFloat64(o.Name)
121125
case *net.IP:
122-
return flagset.GetIP(co.Name)
126+
return flagset.GetIP(o.Name)
123127
case *net.IPNet:
124-
return flagset.GetIPNet(co.Name)
128+
return flagset.GetIPNet(o.Name)
125129
case *int:
126-
return flagset.GetInt(co.Name)
130+
return flagset.GetInt(o.Name)
127131
case *int8:
128-
return flagset.GetInt8(co.Name)
132+
return flagset.GetInt8(o.Name)
129133
case *int16:
130-
return flagset.GetInt16(co.Name)
134+
return flagset.GetInt16(o.Name)
131135
case *int32:
132-
return flagset.GetInt32(co.Name)
136+
return flagset.GetInt32(o.Name)
133137
case *int64:
134-
return flagset.GetInt64(co.Name)
138+
return flagset.GetInt64(o.Name)
135139
case *[]int:
136-
return flagset.GetIntSlice(co.Name)
140+
return flagset.GetIntSlice(o.Name)
137141
case *[]int32:
138-
return flagset.GetInt32Slice(co.Name)
142+
return flagset.GetInt32Slice(o.Name)
139143
case *[]int64:
140-
return flagset.GetInt64Slice(co.Name)
144+
return flagset.GetInt64Slice(o.Name)
141145
case *string:
142-
return flagset.GetString(co.Name)
146+
return flagset.GetString(o.Name)
143147
case *[]string:
144-
return flagset.GetStringSlice(co.Name)
148+
return flagset.GetStringSlice(o.Name)
145149
case *uint:
146-
return flagset.GetUint(co.Name)
150+
return flagset.GetUint(o.Name)
147151
case *uint8:
148-
return flagset.GetUint8(co.Name)
152+
return flagset.GetUint8(o.Name)
149153
case *uint16:
150-
return flagset.GetUint16(co.Name)
154+
return flagset.GetUint16(o.Name)
151155
case *uint32:
152-
return flagset.GetUint32(co.Name)
156+
return flagset.GetUint32(o.Name)
153157
case *uint64:
154-
return flagset.GetUint64(co.Name)
158+
return flagset.GetUint64(o.Name)
155159
case *[]uint:
156-
return flagset.GetUintSlice(co.Name)
160+
return flagset.GetUintSlice(o.Name)
157161
default:
158-
return nil, fmt.Errorf("unexpected option type: %T", co.ConfigKey)
162+
return nil, fmt.Errorf("unexpected option type: %T", o.ConfigKey)
159163
}
160164
}
161165

162166
// UsageText returns the string to use for the usage text of the option. The
163-
// string returned will be the Usage defined on the ConfigOption, along with
167+
// string returned will be the Usage defined on the Option, along with
164168
// the environment variable.
165-
func (co *ConfigOption) UsageText() string {
166-
envVar, hasEnvVar := co.getEnvKey()
169+
func (o *Option) UsageText() string {
170+
envVar, hasEnvVar := o.getEnvKey()
167171
if hasEnvVar {
168-
return fmt.Sprintf("%s (%s)", co.Usage, envVar)
169-
} else {
170-
return co.Usage
172+
return fmt.Sprintf("%s (%s)", o.Usage, envVar)
171173
}
174+
return o.Usage
172175
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Config struct {
7171
MaxGetFeeStatsExecutionDuration time.Duration
7272

7373
// We memoize these, so they bind to pflags correctly
74-
optionsCache *ConfigOptions
74+
optionsCache *Options
7575
flagset *pflag.FlagSet
7676
}
7777

File renamed without changes.

cmd/soroban-rpc/internal/config/config_option.go renamed to cmd/soroban-rpc/internal/config/option.go

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ import (
1212
"github.com/stellar/go/support/strutils"
1313
)
1414

15-
// ConfigOptions is a group of ConfigOptions that can be for convenience
15+
// Options is a group of Options that can be for convenience
1616
// initialized and set at the same time.
17-
type ConfigOptions []*ConfigOption
17+
type Options []*Option
1818

1919
// Validate all the config options.
20-
func (options ConfigOptions) Validate() error {
21-
var missingOptions []errMissingRequiredOption
20+
func (options Options) Validate() error {
21+
var missingOptions []missingRequiredOptionError
2222
for _, option := range options {
2323
if option.Validate != nil {
2424
err := option.Validate(option)
2525
if err == nil {
2626
continue
2727
}
28-
if missingOption, ok := err.(errMissingRequiredOption); ok {
29-
missingOptions = append(missingOptions, missingOption)
28+
var missingOptionErr missingRequiredOptionError
29+
if ok := errors.As(err, &missingOptionErr); ok {
30+
missingOptions = append(missingOptions, missingOptionErr)
3031
continue
3132
}
3233
return errors.New("Invalid config value for " + option.Name)
@@ -39,28 +40,36 @@ func (options ConfigOptions) Validate() error {
3940
errString += "\n*\t" + missingOpt.strErr
4041
errString += "\n \t" + missingOpt.usage
4142
}
42-
return &errMissingRequiredOption{strErr: errString}
43+
return &missingRequiredOptionError{strErr: errString}
4344
}
4445
return nil
4546
}
4647

47-
// ConfigOption is a complete description of the configuration of a command line option
48-
type ConfigOption struct {
49-
Name string // e.g. "database-url"
50-
EnvVar string // e.g. "DATABASE_URL". Defaults to uppercase/underscore representation of name
51-
TomlKey string // e.g. "DATABASE_URL". Defaults to uppercase/underscore representation of name. - to omit from toml
52-
Usage string // Help text
53-
DefaultValue interface{} // A default if no option is provided. Omit or set to `nil` if no default
54-
ConfigKey interface{} // Pointer to the final key in the linked Config struct
55-
CustomSetValue func(*ConfigOption, interface{}) error // Optional function for custom validation/transformation
56-
Validate func(*ConfigOption) error // Function called after loading all options, to validate the configuration
57-
MarshalTOML func(*ConfigOption) (interface{}, error)
48+
// Option is a complete description of the configuration of a command line option
49+
type Option struct {
50+
// e.g. "database-url"
51+
Name string
52+
// e.g. "DATABASE_URL".Defaults to uppercase/underscore representation of name
53+
EnvVar string
54+
// e.g. "DATABASE_URL". Defaults to uppercase/underscore representation of name. - to omit from toml
55+
TomlKey string
56+
// Help text
57+
Usage string
58+
// A default if no option is provided. Omit or set to `nil` if no default
59+
DefaultValue interface{}
60+
// Pointer to the final key in the linked Config struct
61+
ConfigKey interface{}
62+
// Optional function for custom validation/transformation
63+
CustomSetValue func(*Option, interface{}) error
64+
// Function called after loading all options, to validate the configuration
65+
Validate func(*Option) error
66+
MarshalTOML func(*Option) (interface{}, error)
5867

5968
flag *pflag.Flag // The persistent flag that the config option is attached to
6069
}
6170

6271
// Returns false if this option is omitted in the toml
63-
func (o ConfigOption) getTomlKey() (string, bool) {
72+
func (o Option) getTomlKey() (string, bool) {
6473
if o.TomlKey == "-" || o.TomlKey == "_" {
6574
return "", false
6675
}
@@ -74,7 +83,7 @@ func (o ConfigOption) getTomlKey() (string, bool) {
7483
}
7584

7685
// Returns false if this option is omitted in the env
77-
func (o ConfigOption) getEnvKey() (string, bool) {
86+
func (o Option) getEnvKey() (string, bool) {
7887
if o.EnvVar == "-" || o.EnvVar == "_" {
7988
return "", false
8089
}
@@ -85,7 +94,7 @@ func (o ConfigOption) getEnvKey() (string, bool) {
8594
}
8695

8796
// TODO: See if we can remove CustomSetValue into just SetValue/ParseValue
88-
func (o *ConfigOption) setValue(i interface{}) (err error) {
97+
func (o *Option) setValue(i interface{}) (err error) {
8998
if o.CustomSetValue != nil {
9099
return o.CustomSetValue(o, i)
91100
}
@@ -99,7 +108,7 @@ func (o *ConfigOption) setValue(i interface{}) (err error) {
99108
err = fmt.Errorf("config option setting error ('%s') %v", o.Name, recoverRes)
100109
}
101110
}()
102-
parser := func(option *ConfigOption, i interface{}) error {
111+
parser := func(_ *Option, _ interface{}) error {
103112
return fmt.Errorf("no parser for flag %s", o.Name)
104113
}
105114
switch o.ConfigKey.(type) {
@@ -124,7 +133,7 @@ func (o *ConfigOption) setValue(i interface{}) (err error) {
124133
return parser(o, i)
125134
}
126135

127-
func (o *ConfigOption) marshalTOML() (interface{}, error) {
136+
func (o *Option) marshalTOML() (interface{}, error) {
128137
if o.MarshalTOML != nil {
129138
return o.MarshalTOML(o)
130139
}

0 commit comments

Comments
 (0)