micro

package
v1.0.30 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: BSD-3-Clause Imports: 4 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = Key{}

Functions

func NewTrace

func NewTrace() string

func Reg

func Reg(stype string, factory ServiceFactory)

*

  • 注册服务 *

func WithContext

func WithContext(c context.Context, ctx Context) context.Context

Types

type Context

type Context interface {
	Recycle
	Id() string
	Path() string
	Trace() string
	GetValue(key string) string
	SetValue(key string, value string)
	Each(fn func(key string, value string) bool)
	/**
	 * 增加计数,用户统计
	 **/
	AddCount(key string, count int)
	AddTag(key string, value string)
	GetService(name string) (Service, error)
	Runtime() Runtime
	Payload() Payload
	/**
	 * 日志
	 **/
	Println(v ...interface{})
	Printf(format string, v ...interface{})
	Step(step string) Step
	BeginStep(step string)
	EndStep(format string, v ...interface{})
	Ctx() context.Context
	WithValue(key interface{}, value interface{}) context.Context
}

*

  • 上下文 *

func GetContext

func GetContext(c context.Context) Context

type Executor added in v1.0.16

type Executor interface {
	Scheme(ctx Context) IScheme
	Exec(ctx Context, name string, data interface{}) (interface{}, error)
}

type HttpContent added in v1.0.26

type HttpContent struct {
	Code    int               `json:"code"`
	Headers map[string]string `json:"headers"`
	Body    []byte            `json:"body"`
}

func (*HttpContent) Error added in v1.0.26

func (s *HttpContent) Error() string

type IScheme added in v1.0.20

type IScheme interface {
}

type Key

type Key struct{}

type Payload

type Payload interface {
	SetConfig(config interface{}) error
	NewContext(name string, trace string) (Context, error)
	Exit()

	GetValue(key string) interface{}
	SetValue(key string, value interface{})
}

type Recycle

type Recycle interface {
	/**
	 * 资源回收
	 **/
	Recycle()
}

*

  • 资源回收 *

type Runtime

type Runtime interface {
	/**
	 * 配置信息
	 **/
	Config() interface{}
	/**
	 * 名称
	 **/
	Name() string
	/**
	 * 节点
	 **/
	Node() string
	/**
	 * 创建唯一ID
	 **/
	NewID() int64
	/**
	 * 区域ID
	 **/
	Aid() int64
	/**
	 * 节点ID
	 **/
	Nid() int64
	/**
	 * 新建上下文
	 **/
	NewContext(path string, trace string) Context
	/**
	 * 获取服务
	 **/
	GetService(name string) (Service, error)
	/**
	 * 获取服务运行器
	 **/
	GetExecutor(name string) (Executor, error)
	/**
	 * 退出
	 **/
	Exit()
	/**
	 * 退出, 退出后 C <- 1
	 **/
	ExitWait(C chan int8)

	GetValue(key string) interface{}
	SetValue(key string, value interface{})
}

*

  • 运行时 *

type Scheme added in v1.0.19

type Scheme struct {
	Name    string                   `json:"name"`
	Items   []*SchemeItem            `json:"items"`
	Objects map[string]*SchemeObject `json:"objects"`
}

type SchemeField added in v1.0.19

type SchemeField struct {
	Type     string `json:"type"`
	Name     string `json:"name"`
	Title    string `json:"title"`
	Required bool   `json:"required"`
}

type SchemeItem added in v1.0.19

type SchemeItem struct {
	Name   string        `json:"name"`
	Task   *SchemeObject `json:"task"`
	Result *SchemeObject `json:"result"`
}

type SchemeObject added in v1.0.19

type SchemeObject struct {
	Fields []*SchemeField `json:"fields"`
}

type Service

type Service interface {
	Recycle
	/**
	 * 服务名称
	 **/
	Name() string
	/**
	 * 服务配置
	 **/
	Config() interface{}
	/**
	 * 初始化服务
	 **/
	OnInit(ctx Context) error
	/**
	 * 校验服务是否可用
	 **/
	OnValid(ctx Context) error
}

*

  • 服务 *

func NewService

func NewService(stype string, name string, config interface{}) (Service, error)

*

  • 创建服务 *

type ServiceFactory

type ServiceFactory func(name string, config interface{}) (Service, error)

type Step

type Step = func(format string, v ...interface{})

Jump to

Keyboard shortcuts

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