Skip to content

Commit 1073d97

Browse files
committed
Add Validate method to ServerConfig
This adds a new Validate method that checks the getListenConfig call so that the new SO_REUSEPORT stuff fails in dry run on Windows Signed-off-by: sinkingpoint <[email protected]>
1 parent 4285bb8 commit 1073d97

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

config/confighttp/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ type AuthConfig struct {
127127
_ struct{}
128128
}
129129

130+
func (sc *ServerConfig) Validate() error {
131+
_, err := sc.getListenConfig()
132+
if err != nil {
133+
return err
134+
}
135+
136+
return nil
137+
}
138+
130139
// ToListener creates a net.Listener.
131140
func (sc *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) {
132141
cfg, err := sc.getListenConfig() // See listen_config_*.go for platform-specific implementations

config/confighttp/server_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,3 +1224,16 @@ func TestServerReusePort(t *testing.T) {
12241224
})
12251225
}
12261226
}
1227+
1228+
func TestServerConfigValidate(t *testing.T) {
1229+
sc := &ServerConfig{
1230+
Endpoint: "localhost:4318",
1231+
ReusePort: true,
1232+
}
1233+
1234+
if runtime.GOOS == "windows" {
1235+
require.Error(t, sc.Validate())
1236+
} else {
1237+
require.NoError(t, sc.Validate())
1238+
}
1239+
}

0 commit comments

Comments
 (0)