Skip to content

Commit fb07340

Browse files
fix(main): remove colon from constant defaultPort
- Remove colon from constant and add it when used. - Test updated to reflect change While Gin expects the colon to be included in the address parameter, it is better to implement this rather than assume it's part of the port string value.
1 parent ce7574d commit fb07340

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cmd/server/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515

1616
// Constants defining default configuration values and environment variable names.
1717
const (
18-
defaultPort = ":8080" // defaultPort is the default server port if PORT is unset.
18+
defaultPort = "8080" // defaultPort is the default server port if PORT is unset.
1919
trustedProxiesEnv = "TRUSTED_PROXIES" // trustedProxiesEnv is the environment variable for trusted proxy IPs.
2020
staticDirEnv = "STATIC_DIR" // staticDirEnv is the environment variable for the static directory.
2121
defaultStaticDir = "static" // defaultStaticDir is the default static directory relative to the project root.
2222
)
2323

2424
// Config holds server configuration parameters.
2525
type Config struct {
26-
Port string // Port is the server listening port (e.g., ":8080").
26+
Port string // Port is the server listening port (e.g., "8080").
2727
TrustedProxies []string // TrustedProxies lists IP addresses of trusted reverse proxies.
2828
StaticDir string // StaticDir is the directory containing static files.
2929
}
@@ -32,7 +32,7 @@ type Config struct {
3232
// It defaults to port ":8080" if PORT is unset and processes TRUSTED_PROXIES as a comma-separated list,
3333
// trimming whitespace, logging warnings for empty entries, and filtering them out. Returns the configuration and any error encountered.
3434
func LoadConfig() (Config, error) {
35-
config := Config{Port: defaultPort, StaticDir: defaultStaticDir}
35+
config := Config{Port: ":" + defaultPort, StaticDir: defaultStaticDir}
3636
if port := os.Getenv("PORT"); port != "" {
3737
config.Port = ":" + port
3838
}

cmd/server/main_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func TestLoadConfig(t *testing.T) {
229229
portEnv: "",
230230
trustedProxies: "",
231231
staticDirEnv: "",
232-
wantPort: defaultPort,
232+
wantPort: ":" + defaultPort,
233233
wantProxies: nil,
234234
wantStaticDir: filepath.Join(filepath.Dir(os.Args[0]), defaultStaticDir), // Approximation
235235
},
@@ -247,7 +247,7 @@ func TestLoadConfig(t *testing.T) {
247247
portEnv: "",
248248
trustedProxies: "",
249249
staticDirEnv: "/custom/static",
250-
wantPort: defaultPort,
250+
wantPort: ":" + defaultPort,
251251
wantProxies: nil,
252252
wantStaticDir: "/custom/static",
253253
},

0 commit comments

Comments
 (0)