infra

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	VersionKey     string = "version"
	StartupTimeKey string = "startup_time"
)

Variables

View Source
var (
	// DEBUG enable debug mode for glacier
	DEBUG = false
	// WARN enable warning log for glacier
	WARN = true
	// PrintGraph enable print graph
	PrintGraph = false
)

Functions

func WithCondition

func WithCondition(init interface{}, onCondition interface{}) ioc.Conditional

Types

type Binder

type Binder ioc.Binder

type CompleteService

type CompleteService interface {
	Service
	Initializer
	Stoppable
	Reloadable
	Nameable
}

CompleteService is an interface for a service which implements all service interface

type Container

type Container ioc.Container

type DaemonProvider

type DaemonProvider interface {
	Provider
	// Daemon is an async method called after boot
	// this method is called asynchronous and concurrent
	Daemon(ctx context.Context, resolver Resolver)
}

type FlagContext

type FlagContext interface {
	String(name string) string
	StringSlice(name string) []string
	Bool(name string) bool
	Int(name string) int
	IntSlice(name string) []int
	Duration(name string) time.Duration
	Float64(name string) float64
	FlagNames() (names []string)
}

type Glacier

type Glacier interface {
	SetLogger(logger Logger) Glacier

	// WithFlagContext 设置 FlagContext,支持覆盖 FlagContext 默认实现
	// 参数 fn 只支持 `func(...) infra.FlagContext` 形式
	WithFlagContext(fn interface{}) Glacier

	// Provider 注册一个模块
	Provider(providers ...Provider)
	// Service 注册一个 Service
	Service(services ...Service)
	// Async 注册一个异步任务
	Async(asyncJobs ...interface{})

	// Graceful 设置优雅停机实现
	Graceful(builder func() Graceful) Glacier

	// OnServerReady call a function a server ready
	OnServerReady(ffs ...interface{})

	// Start 应用入口
	Start(cliCtx FlagContext) error
	// Init Glacier 初始化之前执行,一般用于设置一些基本配置,比如日志等
	Init(f func(fc FlagContext) error) Glacier
	// BeforeServerStop 服务停止前的回调
	BeforeServerStop(f func(resolver Resolver) error) Glacier
	PreBind(fn func(binder Binder)) Glacier

	Singleton(ins ...interface{}) Glacier
	Prototype(ins ...interface{}) Glacier
	Resolve(resolver interface{}) error
	MustResolve(resolver interface{})
	Container() Container
	Resolver() Resolver
	Binder() Binder
}

type Graceful

type Graceful interface {
	AddReloadHandler(h func())
	AddShutdownHandler(h func())
	// AddPreShutdownHandler 在所有服务停止之前执行,用于执行一些清理操作,该操作会阻塞服务停止,直到该操作完成,不受超时时间限制
	AddPreShutdownHandler(h func())
	Reload()
	Shutdown()
	Start() error
}

type GraphvizNode

type GraphvizNode struct {
	Name       string
	Style      GraphvizNodeStyle
	ParentNode []*GraphvizNode
	Async      bool
	Type       GraphvizNodeType
}

type GraphvizNodeStyle

type GraphvizNodeStyle string
const (
	GraphvizNodeStyleError     GraphvizNodeStyle = `[fillcolor = "red"]`
	GraphvizNodeStyleHook      GraphvizNodeStyle = `[fillcolor = "darkturquoise"]`
	GraphvizNodeStyleImportant GraphvizNodeStyle = `[fillcolor = "chartreuse"]`
)

type GraphvizNodeType

type GraphvizNodeType string
const (
	GraphvizNodeTypeNode         GraphvizNodeType = "node"
	GraphvizNodeTypeClusterStart GraphvizNodeType = "cluster_start"
	GraphvizNodeTypeClusterEnd   GraphvizNodeType = "cluster_end"
)

type GraphvizNodes

type GraphvizNodes []*GraphvizNode

func (GraphvizNodes) Draw

func (nodes GraphvizNodes) Draw() string

type Hook

type Hook interface {
	// OnServerReady call a function a server ready
	OnServerReady(ffs ...interface{})
}

type Initializer

type Initializer interface {
	Init(resolver Resolver) error
}

Initializer is an interface for service initializer

type ListenerBuilder

type ListenerBuilder interface {
	Build(resolver Resolver) (net.Listener, error)
}

type Logger

type Logger interface {
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Warning(v ...interface{})
	Warningf(format string, v ...interface{})
	// Critical 关键性错误,遇到该日志输出时,应用直接退出
	Critical(v ...interface{})
	// Criticalf 关键性错误,遇到该日志输出时,应用直接退出
	Criticalf(format string, v ...interface{})
}

type Nameable

type Nameable interface {
	Name() string
}

Nameable is an interface for service/provider name

type Priority

type Priority interface {
	Priority() int
}

Priority 优先级接口 实现该接口后,在加载 Provider/Service 时,会按照 Priority 大小依次加载(值越小越先加载)

type Provider

type Provider interface {
	// Register add some dependency for current module
	// this method is called one by one synchronous
	// service provider don't autowired in this stage
	Register(binder Binder)
}

type ProviderAggregate

type ProviderAggregate interface {
	Aggregates() []Provider
}

ProviderAggregate Provider 聚合,所有实现该接口的 Provider 在加载之前将会先加载该集合中的 Provider

type ProviderBoot

type ProviderBoot interface {
	// Boot starts the module
	// this method is called one by one synchronous after all register methods called
	// service provider has been autowired in this stage
	Boot(resolver Resolver)
}

type Reloadable

type Reloadable interface {
	Reload()
}

Reloadable is an interface for reloadable service

type Resolver

type Resolver ioc.Resolver

type Service

type Service interface {
	// Start service, not blocking
	Start() error
}

Service is an interface for service

type Stoppable

type Stoppable interface {
	Stop()
}

Stoppable is an interface for service that can be stopped

Jump to

Keyboard shortcuts

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