Skip to content

Commit

Permalink
Extract listenFixedPort function
Browse files Browse the repository at this point in the history
  • Loading branch information
punmechanic committed Mar 26, 2024
1 parent 7bf7c07 commit 7555b79
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cli/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func ListenAnyPort(broadcastAddr string, ports []string) func(ctx context.Contex
}
}

func listenFixedPort(ctx context.Context) (net.Listener, error) {
var lc net.ListenConfig
sock, err := lc.Listen(ctx, "tcp4", net.JoinHostPort("0.0.0.0", "57468"))
return sock, err
}

type RedirectionFlowHandler struct {
Config *oauth2.Config
OnDisplayURL func(url string) error
Expand All @@ -205,11 +211,7 @@ func (r RedirectionFlowHandler) HandlePendingSession(ctx context.Context, challe
}

if r.Listen == nil {
r.Listen = func(ctx context.Context) (net.Listener, error) {
var lc net.ListenConfig
sock, err := lc.Listen(ctx, "tcp4", net.JoinHostPort("0.0.0.0", "57468"))
return sock, err
}
r.Listen = listenFixedPort
}

sock, err := r.Listen(ctx)
Expand Down

0 comments on commit 7555b79

Please sign in to comment.