MCPcopy Create free account
hub / github.com/coderanger/migrations-operator / Start

Method Start

http/http.go:39–74  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

37}
38
39func (s *apiServer) Start(ctx context.Context) error {
40 mux := http.NewServeMux()
41 mux.Handle("/api/ready", &readyHandler{client: s.client})
42
43 addr := os.Getenv("API_LISTEN")
44 if addr == "" {
45 addr = ":5000"
46 }
47
48 log.Info("serving API server", "addr", addr)
49
50 srv := &http.Server{
51 Addr: addr,
52 Handler: mux,
53 }
54
55 done := make(chan struct{})
56 go func() {
57 <-ctx.Done()
58 log.Info("shutting down API server")
59
60 // TODO: use a context with reasonable timeout
61 if err := srv.Shutdown(context.Background()); err != nil {
62 // Error from closing listeners, or context timeout
63 log.Error(err, "error shutting down the HTTP server")
64 }
65 close(done)
66 }()
67
68 if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
69 return err
70 }
71
72 <-done
73 return nil
74}
75
76func (_ *apiServer) NeedLeaderElection() bool {
77 return false

Callers 1

mainFunction · 0.80

Calls 1

HandleMethod · 0.80

Tested by

no test coverage detected