service

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractService

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

AbstractService 提供服务的基本实现

func NewAbstractService

func NewAbstractService(name string, logger log.Logger) *AbstractService

NewAbstractService 创建抽象服务

func (*AbstractService) Init

func (s *AbstractService) Init() error

Init 初始化服务(默认实现)

func (*AbstractService) Logger

func (s *AbstractService) Logger() log.Logger

Logger 获取服务日志器

func (*AbstractService) Name

func (s *AbstractService) Name() string

Name 获取服务名称

func (*AbstractService) Start

func (s *AbstractService) Start(ctx context.Context) error

Start 启动服务(默认实现)

func (*AbstractService) Stop

func (s *AbstractService) Stop(ctx context.Context) error

Stop 停止服务(默认实现)

type Factory

type Factory interface {
	// Create 创建服务实例
	Create() (Service, error)
	// Type 获取服务类型
	Type() string
}

Factory 服务工厂接口

type Manager

type Manager interface {
	// Register 注册服务
	Register(Service) error
	// Get 获取指定服务
	Get(name string) (Service, bool)
	// Start 启动所有服务
	Start(context.Context) error
	// Stop 停止所有服务
	Stop(context.Context) error
}

Manager 服务管理器

func NewManager

func NewManager(logger log.Logger) Manager

NewManager 创建服务管理器

type Service

type Service interface {
	// Init 初始化服务
	Init() error
	// Start 启动服务
	Start(context.Context) error
	// Stop 停止服务
	Stop(context.Context) error
	// Name 获取服务名称
	Name() string
}

Service 定义了一个服务的基本接口

Jump to

Keyboard shortcuts

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