Documentation ¶
Index ¶
- Constants
- Variables
- func DoMonitor(duration int, callback func(*MonitorStat))
- func GenerateLoggerForModule(server *Server, module string) func() logging.ILogger
- type ComponentStatus
- type ElementKey
- type EmptyComponent
- func (c *EmptyComponent) GetSubscribeServiceList() []string
- func (c *EmptyComponent) Init(server *Server) error
- func (c *EmptyComponent) Name() string
- func (c *EmptyComponent) OnConfigChanged(*platformConf.NodeConfig) error
- func (c *EmptyComponent) OnServiceChanged(services []model.SubscribeService, err error)
- func (c *EmptyComponent) PostInit(ctx context.Context) error
- func (c *EmptyComponent) PostStart(ctx context.Context) error
- func (c *EmptyComponent) PostStop(ctx context.Context) error
- func (c *EmptyComponent) PreInit(ctx context.Context) error
- func (c *EmptyComponent) PreStart(ctx context.Context) error
- func (c *EmptyComponent) PreStop(ctx context.Context) error
- func (c *EmptyComponent) SetDynamicConfig(*platformConf.NodeConfig) error
- func (c *EmptyComponent) SetupHandler(root echoswagger.ApiRoot, base string) error
- func (c *EmptyComponent) Start(ctx context.Context) error
- func (c *EmptyComponent) Status() *ComponentStatus
- func (c *EmptyComponent) Stop(ctx context.Context) error
- type Health
- type IComponent
- type MonitorStat
- type Server
- type Status
Constants ¶
const ( // PlatformConfigDataID is dataID of platform config in nacos PlatformConfigDataID = "PLATFORM_CONF" // PlatformConfigGroup is group of platform in nacos PlatformConfigGroup = "PLATFORM_GROUP" )
Variables ¶
var ( // ErrNeedRestart will notify micro to restart when onConfigChanged ErrNeedRestart = errors.New("need restart") )
var GossipKVCacheElementKey = ElementKey("GossipKVCacheComponent")
GossipKVCacheElementKey is ElementKey for GossipKVCache
var LoggerGroupElementKey = ElementKey("LoggerGroupComponent")
LoggerGroupElementKey is ElementKey for LoggerGroup
var LoggingElementKey = ElementKey("LoggingComponent")
LoggingElementKey is ElementKey for logging
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
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 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) 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
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) RegisterElement ¶
func (m *Server) RegisterElement(key, val interface{})
RegisterElement register an element(not component) of 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