mirror of
https://github.com/hanzoai/functions.git
synced 2026-10-30 15:04:37 +00:00
Module github.com/fission/fission -> github.com/hanzoai/functions (288 files). CRD API group fission.io -> hanzo.ai (67 files): functions.hanzo.ai, environments.hanzo.ai, httptriggers.hanzo.ai, messagequeuetriggers.hanzo.ai, joining apps.hanzo.ai under the one house group. Doc URLs preserved. Builds green. Matches the cloud contract: clients/functions, /v1/functions, App CR role "function". Remaining: fork the env images + the live CRD-group migration (demo-only today, low risk).
39 lines
914 B
Go
39 lines
914 B
Go
package httpserver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/hanzoai/functions/pkg/utils/manager"
|
|
)
|
|
|
|
func StartServer(ctx context.Context, log *zap.Logger, mgr manager.Interface, svc string, port string, handler http.Handler) {
|
|
if !strings.Contains(port, ":") {
|
|
port = fmt.Sprintf(":%s", port)
|
|
}
|
|
server := http.Server{
|
|
Addr: port,
|
|
Handler: handler,
|
|
}
|
|
l := log.With(zap.String("service", svc), zap.String("addr", server.Addr))
|
|
l.Info("starting server")
|
|
mgr.Add(ctx, func(ctx context.Context) {
|
|
if err := server.ListenAndServe(); err != nil {
|
|
if err != http.ErrServerClosed {
|
|
l.Error("server error", zap.Error(err))
|
|
}
|
|
}
|
|
})
|
|
<-ctx.Done()
|
|
l.Info("shutting down server")
|
|
if err := server.Shutdown(ctx); err != nil {
|
|
if err != context.Canceled && err != context.DeadlineExceeded {
|
|
l.Error("server shutdown error", zap.Error(err))
|
|
}
|
|
}
|
|
}
|