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 {
|
func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
addr, err := addrflag(cmd.String("ip"), cmd.Uint("p"))
|
addr, err := addrflag(cmd.String("ip"), cmd.Uint("p"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -170,6 +171,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
slog.InfoContext(ctx, "HTTP API server", slog.Any("addr", l.Addr()))
|
slog.InfoContext(ctx, "HTTP API server", slog.Any("addr", l.Addr()))
|
||||||
|
defer cancel()
|
||||||
err := srv.Serve(l)
|
err := srv.Serve(l)
|
||||||
if err == http.ErrServerClosed {
|
if err == http.ErrServerClosed {
|
||||||
return
|
return
|
||||||
@ -189,7 +191,7 @@ func cliJoin(ctx context.Context, cmd *cli.Command) error {
|
|||||||
}()
|
}()
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
t.Stop()
|
t.Stop()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return srv.Shutdown(ctx)
|
return srv.Shutdown(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user