Documentation ¶
Index ¶
- Constants
- Variables
- func AddShutdownListener(fn func()) (waitForCalled func())
- func AddWrapUpListener(fn func()) (waitForCalled func())
- func Chain(fns ...func() error) error
- func DoWithTimeout(fn func() error, timeout time.Duration, opts ...DoOption) error
- func GoSafe(fn func())
- func Hash(data []byte) uint64
- func LoadFile(file string) []byte
- func Md5(data []byte) []byte
- func Md5Hex(data []byte) string
- func NewUuid() string
- func Parallel(fns ...func())
- func PrintStack()
- func Recover(cleanups ...func())
- func RunSafe(fn func())
- func SetTimeToForceQuit(duration time.Duration)
- func SetupService()
- func Stack() []byte
- func StartMetricsAgent(addr string)
- type Discovery
- func DiscoveryService(service string) (*Discovery, error)
- func GetService(service string) (*Discovery, error)
- func MustGetService(service string) *Discovery
- func MustPutService(service, addr string, keepalivetimeout int64, register func(*grpc.Server), ...) *Discovery
- func PutService(service, addr string, keepalivetimeout int64, register func(*grpc.Server), ...) (*Discovery, error)
- func (dt *Discovery) Add(service, addr string) error
- func (dt *Discovery) AddWithLease(service, addr string, timeout int64) (<-chan *clientv3.LeaseKeepAliveResponse, error)
- func (dt *Discovery) CloseService()
- func (dt *Discovery) Del(service, addr string) error
- func (dt *Discovery) RunService()
- func (dt *Discovery) String() string
- type DoOption
- type RoutineGroup
- type WorkerGroup
Constants ¶
const ( MeshName = "service.discovery" MeshMeta = "" )
Variables ¶
var ( // ErrCanceled is the error returned when the context is canceled. ErrCanceled = context.Canceled // ErrTimeout is the error returned when the context's deadline passes. ErrTimeout = context.DeadlineExceeded )
------------------------------------------------------------------------------------------ DoWithTimeout
var Logger *logx.Logger
Functions ¶
func AddShutdownListener ¶
func AddShutdownListener(fn func()) (waitForCalled func())
----------------------------------- Add Graceful Shutdown handlers AddShutdownListener adds fn as a shutdown listener. The returned func can be used to wait for fn getting called.
func AddWrapUpListener ¶
func AddWrapUpListener(fn func()) (waitForCalled func())
AddWrapUpListener adds fn as a wrap up listener. The returned func can be used to wait for fn getting called.
func Chain ¶
------------------------------------------------------------------------------------------ Chain runs funs one by one until an error occurred.
func DoWithTimeout ¶
DoWithTimeout runs fn with timeout control.
func GoSafe ¶
func GoSafe(fn func())
GoSafe runs the given fn using another goroutine, recovers if fn panics.
func PrintStack ¶
func PrintStack()
PrintStack prints to standard error the stack trace returned by runtime.Stack.
func SetTimeToForceQuit ¶
SetTimeToForceQuit sets the waiting time before force quitting.
func SetupService ¶
func SetupService()
Types ¶
type Discovery ¶
type Discovery struct { //etcd client Cli *clientv3.Client // grpc server/client Serv *grpc.Server Conn *grpc.ClientConn //endpoints EndMgr endpoints.Manager SrvKey string Addr string // contains filtered or unexported fields }
func DiscoveryService ¶
------------------- Discovery Service Put / Get Service -------------------
func GetService ¶
func MustGetService ¶
func MustPutService ¶
func PutService ¶
func (*Discovery) AddWithLease ¶
func (*Discovery) CloseService ¶
func (dt *Discovery) CloseService()
func (*Discovery) RunService ¶
func (dt *Discovery) RunService()
type DoOption ¶
DoOption defines the method to customize a DoWithTimeout call.
func WithContext ¶
WithContext customizes a DoWithTimeout call with given ctx.
type RoutineGroup ¶
type RoutineGroup struct {
// contains filtered or unexported fields
}
------------------------------------------------------------------------------------------ RoutineGroup A RoutineGroup is used to group goroutines together and all wait all goroutines to be done.
func (*RoutineGroup) Run ¶
func (g *RoutineGroup) Run(fn func())
Run runs the given fn in RoutineGroup. Don't reference the variables from outside, because outside variables can be changed by other goroutines
func (*RoutineGroup) RunSafe ¶
func (g *RoutineGroup) RunSafe(fn func())
RunSafe runs the given fn in RoutineGroup, and avoid panics. Don't reference the variables from outside, because outside variables can be changed by other goroutines
func (*RoutineGroup) Wait ¶
func (g *RoutineGroup) Wait()
Wait waits all running functions to be done.
type WorkerGroup ¶
type WorkerGroup struct {
// contains filtered or unexported fields
}
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ WorkerGroup A WorkerGroup is used to run given number of workers to process jobs.
func NewWorkerGroup ¶
func NewWorkerGroup(job func(), workers int) WorkerGroup
NewWorkerGroup returns a WorkerGroup with given job and workers.