quit on leave
This commit is contained in:
parent
bd2085ee87
commit
c0afd85f11
4
main.go
4
main.go
@ -135,6 +135,7 @@ func addrflag(ip string, p uint64) (netip.AddrPort, error) {
|
||||
}
|
||||
|
||||
func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
addr, err := addrflag(cmd.String("ip"), cmd.Uint("p"))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -170,6 +171,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
||||
}
|
||||
go func() {
|
||||
slog.InfoContext(ctx, "HTTP API server", slog.Any("addr", l.Addr()))
|
||||
defer cancel()
|
||||
err := srv.Serve(l)
|
||||
if err == http.ErrServerClosed {
|
||||
return
|
||||
@ -189,7 +191,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
||||
}()
|
||||
<-ctx.Done()
|
||||
t.Stop()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
return srv.Shutdown(ctx)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user