git.iko.soy/typeable/oauth2-proxy
on ea261ca help sign in
typeable/oauth2-proxy/pkg/http/server_group.go
35 lines 675 B history raw
1package http
3import (
4 "context"
6 "golang.org/x/sync/errgroup"
7)
9// NewServerGroup creates a new Server to start and gracefully stop a collection
10// of Servers.
11func NewServerGroup(servers ...Server) Server {
12 return &serverGroup{
13 servers: servers,
14 }
17// serverGroup manages the starting and graceful shutdown of a collection of
18// servers.
19type serverGroup struct {
20 servers []Server
23// Start runs the servers in the server group.
24func (s *serverGroup) Start(ctx context.Context) error {
25 g, groupCtx := errgroup.WithContext(ctx)
27 for _, server := range s.servers {
28 srv := server
29 g.Go(func() error {
30 return srv.Start(groupCtx)
31 })
32 }
34 return g.Wait()