Documentation ¶
Index ¶
- Variables
- type GoRoutine
- type GoRoutineFn
- type GoRoutineOption
- type HTTP
- func NewDefaultHTTPPProf(l *zap.Logger) *HTTP
- func NewDefaultHTTPProbes(l *zap.Logger, probes map[healthz.Type][]interface{}) *HTTP
- func NewDefaultHTTPPrometheus(l *zap.Logger) *HTTP
- func NewDefaultHTTPReadme(l *zap.Logger, readmers func() []interfaces.Readmer) *HTTP
- func NewDefaultHTTPViper(l *zap.Logger) *HTTP
- func NewDefaultHTTPZap(l *zap.Logger) *HTTP
- func NewHTTP(l *zap.Logger, name, addr string, handler http.Handler, ...) *HTTP
- func NewHTTPPProf(l *zap.Logger, name, addr, path string) *HTTP
- func NewHTTPPrometheus(l *zap.Logger, name, addr, path string) *HTTP
- func NewHTTPReadme(l *zap.Logger, name, addr, path string, readmers func() []interfaces.Readmer) *HTTP
- func NewHTTPViper(l *zap.Logger, c *viper.Viper, name, addr, path string) *HTTP
- func NewHTTPZap(l *zap.Logger, name, addr, path string) *HTTP
- func NewHealthz(l *zap.Logger, name, addr, path string, probes map[healthz.Type][]interface{}) *HTTP
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrServiceNotRunning = errors.New("service not running") ErrServiceShutdown = errors.New("service shutdown") )
View Source
var ( DefaultHTTPHealthzName = "healthz" DefaultHTTPHealthzAddr = ":9400" DefaultHTTPHealthzPath = "/healthz" )
View Source
var ( ErrUnhandledHealthzProbe = errors.New("unhandled healthz probe") ErrProbeFailed = errors.New("probe failed") ErrLivenessProbeFailed = errors.New("liveness probe failed") ErrReadinessProbeFailed = errors.New("readiness probe failed") ErrStartupProbeFailed = errors.New("startup probe failed") )
View Source
var ( DefaultHTTPPProfName = "pprof" DefaultHTTPPProfAddr = "localhost:6060" DefaultHTTPPProfPath = "/debug/pprof" )
View Source
var ( DefaultHTTPPrometheusName = "prometheus" DefaultHTTPPrometheusAddr = ":9200" DefaultHTTPPrometheusPath = "/metrics" )
View Source
var ( DefaultHTTPReadmeName = "readme" DefaultHTTPReadmeAddr = "localhost:9001" DefaultHTTPReadmePath = "/readme" )
View Source
var ( DefaultHTTPViperName = "viper" DefaultHTTPViperAddr = "localhost:9300" DefaultHTTPViperPath = "/config" )
View Source
var ( DefaultHTTPZapName = "zap" DefaultHTTPZapAddr = "localhost:9100" DefaultHTTPZapPath = "/log" )
Functions ¶
This section is empty.
Types ¶
type GoRoutine ¶
type GoRoutine struct {
// contains filtered or unexported fields
}
GoRoutine struct
func NewGoRoutine ¶
func NewGoRoutine(l *zap.Logger, name string, handler GoRoutineFn, opts ...GoRoutineOption) *GoRoutine
Example ¶
var once sync.Once svr := keel.NewServer( keel.WithLogger(zap.NewExample()), keel.WithGracefulPeriod(3*time.Second), ) svr.AddService( service.NewGoRoutine(svr.Logger(), "demo", func(ctx context.Context, l *zap.Logger) error { for { // handle graceful shutdowns if err := ctx.Err(); errors.Is(context.Cause(ctx), service.ErrServiceShutdown) { l.Info("context has been canceled du to graceful shutdow") return nil } else if err != nil { return errors.Wrap(err, "unexpected context error") } l.Info("ping") time.Sleep(700 * time.Millisecond) once.Do(shutdown) } }), ) svr.Run()
Output: {"level":"info","msg":"starting keel server"} {"level":"info","msg":"starting keel service","keel_service_type":"goroutine","keel_service_name":"demo"} {"level":"info","msg":"ping","keel_service_type":"goroutine","keel_service_name":"demo","keel_service_inst":0} {"level":"info","msg":"ping","keel_service_type":"goroutine","keel_service_name":"demo","keel_service_inst":0} {"level":"info","msg":"keel graceful shutdown","graceful_period":"3s"} {"level":"info","msg":"keel graceful shutdown: closers"} {"level":"info","msg":"stopping keel service","keel_service_type":"goroutine","keel_service_name":"demo"} {"level":"info","msg":"context has been canceled du to graceful shutdow","keel_service_type":"goroutine","keel_service_name":"demo","keel_service_inst":0} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"*service.GoRoutine"} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"noop.TracerProvider"} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"noop.MeterProvider"} {"level":"info","msg":"keel graceful shutdown: complete"} {"level":"info","msg":"keel server stopped"}
type GoRoutineOption ¶
type GoRoutineOption func(*GoRoutine)
GoRoutine struct
func GoRoutineWithPralllel ¶
func GoRoutineWithPralllel(v int) GoRoutineOption
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP struct
func NewDefaultHTTPPProf ¶
func NewDefaultHTTPProbes ¶
func NewDefaultHTTPReadme ¶
func NewDefaultHTTPReadme(l *zap.Logger, readmers func() []interfaces.Readmer) *HTTP
func NewDefaultHTTPViper ¶
func NewDefaultHTTPZap ¶
func NewHTTP ¶
func NewHTTP(l *zap.Logger, name, addr string, handler http.Handler, middlewares ...middleware.Middleware) *HTTP
Example ¶
svr := keel.NewServer( keel.WithLogger(zap.NewExample()), keel.WithGracefulPeriod(10*time.Second), ) l := svr.Logger() svr.AddService( service.NewHTTP(l, "demo", "localhost:8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("OK")) })), ) go func() { waitFor("localhost:8080") l.Info(httpGet("http://localhost:8080")) shutdown() }() svr.Run()
Output: {"level":"info","msg":"starting keel server"} {"level":"info","msg":"starting keel service","keel_service_type":"http","keel_service_name":"demo","net_host_ip":"localhost","net_host_port":"8080"} {"level":"info","msg":"OK"} {"level":"info","msg":"keel graceful shutdown","graceful_period":"10s"} {"level":"info","msg":"keel graceful shutdown: closers"} {"level":"info","msg":"stopping keel service","keel_service_type":"http","keel_service_name":"demo"} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"*service.HTTP"} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"noop.TracerProvider"} {"level":"debug","msg":"keel graceful shutdown: closer closed","name":"noop.MeterProvider"} {"level":"info","msg":"keel graceful shutdown: complete"} {"level":"info","msg":"keel server stopped"}
func NewHTTPReadme ¶
func NewHealthz ¶
Click to show internal directories.
Click to hide internal directories.