service

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package service 服务管理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(ctx context.Context) error

Func 服务实际需要执行的函数

实现者需要正确处理 ctx.Done 事件,调用者可能会主动取消函数执行; 如果是通 ctx 取消的,应该返回其错误信息。

type Manager

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

Manager 服务管理

func NewManager

func NewManager() *Manager

NewManager 返回 Manager

func (*Manager) AddService

func (mgr *Manager) AddService(f Func, title string)

AddService 添加新的服务

f 表示服务的运行函数; title 是对该服务的简要说明。

func (*Manager) Run

func (mgr *Manager) Run()

Run 运行所有服务

func (*Manager) Services

func (mgr *Manager) Services() []*Service

Services 返回所有的服务列表

func (*Manager) Stop

func (mgr *Manager) Stop()

Stop 停止所有服务

type Service

type Service struct {
	Title string
	// contains filtered or unexported fields
}

Service 服务模型

func (*Service) Err

func (srv *Service) Err() error

Err 上次的错误信息,不会清空。

func (*Service) Run

func (srv *Service) Run()

Run 开始执行该服务

func (*Service) State

func (srv *Service) State() State

State 获取当前服务的状态

func (*Service) Stop

func (srv *Service) Stop()

Stop 停止服务

type State

type State int8

State 服务的状态值

const (
	Stopped State = iota // 当前处理停止状态,默认状态
	Running              // 正在运行
	Failed               // 出错,不再执行后续操作
)

几种可能的状态值

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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