MCPcopy
hub / github.com/cshum/imagor / RunContext

Method RunContext

server/server.go:106–125  ·  view source on GitHub ↗

RunContext run server with context

(ctx context.Context)

Source from the content-addressed store, hash-verified

104
105// RunContext run server with context
106func (s *Server) RunContext(ctx context.Context) {
107 s.startup(ctx)
108
109 go func() {
110 if err := s.listenAndServe(); err != nil && err != http.ErrServerClosed {
111 s.Logger.Fatal("listen", zap.Error(err))
112 }
113 }()
114 s.Logger.Info("listen", zap.String("addr", s.Addr))
115
116 if !isNil(s.Metrics) {
117 if err := s.Metrics.Startup(ctx); err != nil {
118 s.Logger.Fatal("metrics-startup", zap.Error(err))
119 }
120 }
121
122 <-ctx.Done()
123
124 s.shutdown(context.Background())
125}
126
127func isNil(c any) bool {
128 return c == nil || (reflect.ValueOf(c).Kind() == reflect.Ptr && reflect.ValueOf(c).IsNil())

Callers 2

RunMethod · 0.95
TestServer_RunFunction · 0.80

Calls 8

startupMethod · 0.95
listenAndServeMethod · 0.95
shutdownMethod · 0.95
isNilFunction · 0.85
StringMethod · 0.80
StartupMethod · 0.65
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by 1

TestServer_RunFunction · 0.64