service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 52 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// snowflake type
	SnowflakeType_Default = 0
	SnowflakeType_53      = 1
)
View Source
const (
	InternalServerPathPrefix = "__internal/"
)

etcd prefix used internal by host

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func SetupModule

func SetupModule(provider ModuleProvider, options ...ModuleOption) *Builder

func (*Builder) Build

func (b *Builder) Build() (Host, error)

func (*Builder) SetupModule

func (b *Builder) SetupModule(provider ModuleProvider, options ...ModuleOption) *Builder

func (*Builder) WithOptions

func (b *Builder) WithOptions(options ...Option) *Builder

type EventLogger

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

EventLogger log event object

func (EventLogger) CO

func (el EventLogger) CO(event string, o zapcore.ObjectMarshaler, gtags gTags.Tags)

CO stands for Object. same as O but add new param gTags.

func (*EventLogger) Clone

func (el *EventLogger) Clone() *EventLogger

func (EventLogger) F

func (el EventLogger) F(event string, fields ...zapcore.Field)

F stands for Field, it logs event object by listing event fields one by one

func (EventLogger) O

func (el EventLogger) O(event string, o zapcore.ObjectMarshaler)

O stands for Object, it logs event object that implements zapcore.ObjectMarshaler interface

func (*EventLogger) SetTags

func (el *EventLogger) SetTags(tags gTags.Tags) *EventLogger

func (EventLogger) Sync

func (el EventLogger) Sync() error

type Host

type Host interface {
	Name() string
	Logger() *zap.Logger
	EventLogger() *EventLogger
	ModuleConfig() env.ModuleConfig
	Serve() error
	RegisterModule(moduleName string, addr string, metaData interface{}) error
	GetConfigPath() string
	Metrics() prometheus.Registerer
	EtcdSession() *concurrency.Session
	KVManager() *KVMgr
	Snowflake(ctx context.Context, name string, tp uint32) (Snowflake, error)
	Tags() map[string]string

	Tracer(moduleName string) opentracing.Tracer
	// contains filtered or unexported methods
}

type HostModule

type HostModule interface {
	// GetHost return the host belong to
	GetHost() Host

	// GetModuleHandler return the module handler created during build
	GetModuleHandler() interface{}
}

type KVMgr

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

func (*KVMgr) Delete

func (km *KVMgr) Delete(ctx context.Context, key string) error

Delete key from keys manager

func (*KVMgr) GetOrGenerate

func (km *KVMgr) GetOrGenerate(ctx context.Context, key string, length int) ([]byte, error)

GetOrGenerate get key or generate key if key does not exist atomic

func (*KVMgr) GetOrSet

func (km *KVMgr) GetOrSet(ctx context.Context, key string, val []byte) ([]byte, error)

GetOrSet get key or set key if key does not exist atomic

type Module

type Module interface {
	ModuleServer

	PreServe(ctx context.Context) error
}

type ModuleCloser

type ModuleCloser interface {
	Close(context.Context) error
}

type ModuleCustomizedRegister

type ModuleCustomizedRegister interface {
	// ModuleRegisterName return a string could be used to register path like "{hostName}/{ModuleRegisterName}" used in service discovery
	//  if module don't provide this interface, it will use "{hostName}/{moduleName}" instead
	ModuleRegisterName() string
}

type ModuleDriver

type ModuleDriver interface {
	Host() Host
	HostName() string
	ModuleName() string
	ModuleConfig() env.ModuleConfig
	Logger() *zap.Logger
	EventLogger() *EventLogger
	Metrics() prometheus.Registerer
	Tracer() opentracing.Tracer
}

type ModuleMetaDataConfig

type ModuleMetaDataConfig interface {
	// NewModuleMetadata to create a module config's metadata structure, will be used to unmarshal from config.yaml
	NewModuleMetadata() interface{}
}

type ModuleOption

type ModuleOption func(*moduleOptions)

func WithModuleName

func WithModuleName(name string) ModuleOption

func WithName

func WithName(name string) ModuleOption

func WithProcess

func WithProcess(processType ProcessType, name string, pcf ProcessHandlerCreator) ModuleOption

WithProcess used to help add extra process to module

func WithRole

func WithRole(role string) ModuleOption

type ModuleProcesses

type ModuleProcesses interface {
	SetProcessOptions(options []ProcessOption)
}

type ModuleProvider

type ModuleProvider interface {
	DefaultName() string
	Create(ModuleDriver) (Module, error)
}

ModuleProvider create Module from Host bot provide ModuleProvider other than Module so Module can be created lazily

func ModuleProviderFromFunc

func ModuleProviderFromFunc(name string, cf func(ModuleDriver) (Module, error)) ModuleProvider

type ModuleServer

type ModuleServer interface {
	Serve(context.Context) error
}

type Option

type Option func(h *host)

func WithArgs

func WithArgs(args []string) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

type PreServeHook

type PreServeHook func(ctx context.Context) error

type ProcessHTTPHandler

type ProcessHTTPHandler interface {
	http.Handler
}

ProcessHTTPHandler is used to create http server

type ProcessHTTPPather

type ProcessHTTPPather interface {
	GetPaths() []string
}

ProcessHTTPPather is used to limit the metrics path outputs

type ProcessHandler

type ProcessHandler interface {
}

type ProcessHandlerCreator

type ProcessHandlerCreator func(module ModuleDriver) (ProcessHandler, error)

type ProcessOption

type ProcessOption struct {
	ProcessType ProcessType
	Name        string
	Creator     ProcessHandlerCreator
}

type ProcessType

type ProcessType uint8
const (
	ProcessHTTP ProcessType = iota
)

type Roles

type Roles []string

func (Roles) Support

func (rs Roles) Support(ors Roles) bool

type Snowflake

type Snowflake interface {
	Next() (uint64, error)
}

type Snowflake53

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

func (*Snowflake53) Next

func (sf *Snowflake53) Next() (uint64, error)

Next return snowflake id

Jump to

Keyboard shortcuts

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