cli can pass -p 10_000
This commit is contained in:
@@ -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
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user