cli can pass -p 10_000

This commit is contained in:
Bel LaPointe
2025-05-07 20:22:59 -06:00
parent 49064f1ea2
commit c7375949c2
5 changed files with 21 additions and 12 deletions

View File

@@ -1,14 +1,18 @@
package server
import (
"os"
"strconv"
"context"
)
var Port = func() int {
port, _ := strconv.Atoi(os.Getenv("PORT"))
if port == 0 {
port = 10000
func Inject(ctx context.Context, port int) context.Context {
return context.WithValue(ctx, "server.port", port)
}
func Extract(ctx context.Context) int {
v := ctx.Value("server.port")
port, ok := v.(int)
if !ok {
return 10_000
}
return port
}()
}