advapp

package
v0.0.0-...-575c38c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogFieldKeyName = "__advapp_name"
)

Variables

This section is empty.

Functions

func Main

func Main(app App)

Main 启动一个 App

func WebMain

func WebMain(app WebApp)

WebMain 启动一个 WebMain

Types

type App

type App interface {
	// Checkers 提供一组健康检查,用于响应 HTTP 健康检查接口
	Checkers() []Checker
	// Run 提供服务主运行方法,正常情况下,此方法需要长期运行
	Run(ctx context.Context, ld advconf.Loader) (err error)
	// Stop 提供停止方法,执行该方法后,Run 方法应该优雅退出,且没有 error 返回
	Stop(ctx context.Context) (err error)
}

App App 接口用于抽象最基础的业务服务,包含健康检查,运行和停止三个方法

func WrapWebApp

func WrapWebApp(app WebApp) App

WrapWebApp 将一个 WebApp 包装为 App 用以执行 Main 方法

type Check

type Check struct {
	// contains filtered or unexported fields
}

Check 健康检查工具

func NewCheck

func NewCheck(opts CheckOptions) *Check

NewCheck 创建健康检查工具

func (*Check) Alive

func (c *Check) Alive(rw http.ResponseWriter, r *http.Request)

Alive 提供存活检查的 http.HandlerFunc

func (*Check) Mount

func (c *Check) Mount(m *http.ServeMux)

Mount 将健康检查挂载在 http.ServeMux

func (*Check) Ready

func (c *Check) Ready(rw http.ResponseWriter, r *http.Request)

Ready 提供就绪检查的 http.HandlerFunc

type CheckOptions

type CheckOptions struct {
	// Checkers 健康检查条目
	Checkers []Checker
	// Cascade 级联值,如果连续 Ready 失败次数超过这个值会触发 Alive 失败
	Cascade int64
}

CheckOptions Check 构建参数

type Checker

type Checker interface {
	Check(ctx context.Context) error
}

Checker 抽象一个健康检查条目

type CheckerFunc

type CheckerFunc func(ctx context.Context) error

CheckerFunc 健康检查函数

func (CheckerFunc) Check

func (cf CheckerFunc) Check(ctx context.Context) error

type WebApp

type WebApp interface {
	// Checkers 提供一组健康检查,用于响应 HTTP 健康检查接口
	Checkers() []Checker
	// Setup 提供初始化依赖项方法
	Setup(ctx context.Context, ld advconf.Loader) (err error)
	// Route 提供挂载路由方法
	Route(ctx context.Context, g *echo.Group)
	// Teardown 提供停止方法,且没有必要返回 error
	Teardown(ctx context.Context)
}

WebApp WebApp 接口用于抽象 Web 服务,包含健康检查,依赖项初始化,路由挂载和停止方法

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL