micro

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 34 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// PlatformConfigDataID is dataID of platform config in nacos
	PlatformConfigDataID = "PLATFORM_CONF"
	// PlatformConfigGroup is group of platform in nacos
	PlatformConfigGroup = "PLATFORM_GROUP"
)

Variables

View Source
var (
	// ErrNeedRestart will notify micro to restart when onConfigChanged
	ErrNeedRestart = errors.New("need restart")
)
View Source
var GossipKVCacheElementKey = ElementKey("GossipKVCacheComponent")

GossipKVCacheElementKey is ElementKey for GossipKVCache

View Source
var LoggerGroupElementKey = ElementKey("LoggerGroupComponent")

LoggerGroupElementKey is ElementKey for LoggerGroup

View Source
var LoggingElementKey = ElementKey("LoggingComponent")

LoggingElementKey is ElementKey for logging

View Source
var NacosClientElementKey = ElementKey("NacosClient")

NacosClientElementKey is ElementKey for nacos client

Functions

func DoMonitor

func DoMonitor(duration int, callback func(*MonitorStat))

DoMonitor start a loop for monitor

func GenerateLoggerForModule

func GenerateLoggerForModule(server *Server, module string) func() logging.ILogger

GenerateLoggerForModule generate a func for get logger for module w/ logger or logger group

Types

type ComponentStatus

type ComponentStatus struct {
	IsOK   bool                   `json:"is_ok,omitempty"`
	Params map[string]interface{} `json:"params,omitempty"`
}

ComponentStatus is status of component

type ElementKey

type ElementKey string

ElementKey is type of key of element (not component)

type EmptyComponent

type EmptyComponent struct {
	IsPrint bool
}

EmptyComponent is the base implementation of IComponent

func (*EmptyComponent) GetSubscribeServiceList

func (c *EmptyComponent) GetSubscribeServiceList() []string

GetSubscribeServiceList returns the service that the component need to subscribe

func (*EmptyComponent) Init

func (c *EmptyComponent) Init(server *Server) error

Init the component

func (*EmptyComponent) Name

func (c *EmptyComponent) Name() string

Name of the component

func (*EmptyComponent) OnConfigChanged

func (c *EmptyComponent) OnConfigChanged(*platformConf.NodeConfig) error

OnConfigChanged called when dynamic config changed

func (*EmptyComponent) OnServiceChanged

func (c *EmptyComponent) OnServiceChanged(services []model.SubscribeService, err error)

OnServiceChanged called when subscribe service changed

func (*EmptyComponent) PostInit

func (c *EmptyComponent) PostInit(ctx context.Context) error

PostInit called after Init()

func (*EmptyComponent) PostStart

func (c *EmptyComponent) PostStart(ctx context.Context) error

PostStart called after Start()

func (*EmptyComponent) PostStop

func (c *EmptyComponent) PostStop(ctx context.Context) error

PostStop called after Stop()

func (*EmptyComponent) PreInit

func (c *EmptyComponent) PreInit(ctx context.Context) error

PreInit called before Init()

func (*EmptyComponent) PreStart

func (c *EmptyComponent) PreStart(ctx context.Context) error

PreStart called before Start()

func (*EmptyComponent) PreStop

func (c *EmptyComponent) PreStop(ctx context.Context) error

PreStop called before Stop()

func (*EmptyComponent) SetDynamicConfig

func (c *EmptyComponent) SetDynamicConfig(*platformConf.NodeConfig) error

SetDynamicConfig called when get dynamic config for the first time

func (*EmptyComponent) SetupHandler

func (c *EmptyComponent) SetupHandler(root echoswagger.ApiRoot, base string) error

SetupHandler of echo if the component need

func (*EmptyComponent) Start

func (c *EmptyComponent) Start(ctx context.Context) error

Start the component

func (*EmptyComponent) Status

func (c *EmptyComponent) Status() *ComponentStatus

Status of the component

func (*EmptyComponent) Stop

func (c *EmptyComponent) Stop(ctx context.Context) error

Stop the component

type Health

type Health struct {
	IsHealth bool `json:"health"`
}

Health haelth

func GetHealth

func GetHealth(address string) (*Health, error)

GetHealth get Health

type IComponent

type IComponent interface {
	// Name of the component
	Name() string

	// Status of the component
	Status() *ComponentStatus

	// PreInit called before Init()
	PreInit(ctx context.Context) error

	// Init the component
	Init(server *Server) error

	// PostInit called after Init()
	PostInit(ctx context.Context) error

	// SetDynamicConfig called when get dynamic config for the first time
	SetDynamicConfig(*platformConf.NodeConfig) error

	// OnConfigChanged called when dynamic config changed
	OnConfigChanged(*platformConf.NodeConfig) error

	// GetSubscribeServiceList returns the service that the component need to subscribe
	GetSubscribeServiceList() []string

	// OnServiceChanged called when subscribe service changed
	OnServiceChanged(services []model.SubscribeService, err error)

	// SetupHandler of echo if the component need
	SetupHandler(root echoswagger.ApiRoot, base string) error

	// PreStart called before Start()
	PreStart(ctx context.Context) error

	// Start the component
	Start(ctx context.Context) error

	// PostStart called after Start()
	PostStart(ctx context.Context) error

	// PreStop called before Stop()
	PreStop(ctx context.Context) error

	// Stop the component
	Stop(ctx context.Context) error

	// PostStop called after Stop()
	PostStop(ctx context.Context) error
}

IComponent is interface of component

type MonitorStat

type MonitorStat struct {
	runtime.MemStats
	LiveObjects  uint64 `json:"live_objects,omitempty"`  // Live objects = malloc - Frees
	NumGoroutine int    `json:"num_goroutine,omitempty"` // Number of goroutines
}

MonitorStat is the state of the runtime

type Server

type Server struct {
	AppName    string
	AppVersion string

	PrivateIP      net.IP
	PrivateCluster string
	GlobalIP       net.IP
	GlobalCluster  string
	FlagSet        *pflag.FlagSet

	GzipSkipper func(uri string) bool
	// APIRateSkipper defime rate limiter skipper
	APIRateSkipper func(uri string) bool
	// APIBodySkipper define request Body Content-length limit Skipper
	APIBodySkipper func(uri string) bool
	// APITimeOutSkipper define timeout Skipper
	APITimeOutSkipper func(uri string) bool
	// contains filtered or unexported fields
}

Server serve as a server composed by components

func NewServer

func NewServer(appname, appversion string, components []IComponent) (*Server, error)

NewServer create a MicroServer

func (*Server) GetElement

func (m *Server) GetElement(key interface{}) interface{}

GetElement return an element(not component) from micro server

func (*Server) GetStatus

func (m *Server) GetStatus() Status

GetStatus of the micro server

func (*Server) Init

func (m *Server) Init() error

Init the micro server

func (*Server) RegisterElement

func (m *Server) RegisterElement(key, val interface{})

RegisterElement register an element(not component) of micro server

func (*Server) Run

func (m *Server) Run() error

Run the micro server until fetch SIGINT or SIGTERM signal

func (*Server) StartServe

func (m *Server) StartServe() error

StartServe start the micro server

func (*Server) StopServe

func (m *Server) StopServe() error

StopServe stop the micro server

type Status

type Status struct {
	IsOK       bool                        `json:"is_ok,omitempty"`
	Basic      *conf.BasicConfig           `json:"basic,omitempty"`
	Components map[string]*ComponentStatus `json:"components,omitempty"`
}

Status is status of micro

func GetStatus

func GetStatus(address string) (*Status, error)

GetStatus get Status

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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