app

package
v0.0.0-...-4dde864 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// General settings
	ConfigFileFlag = cli.StringFlag{
		Name:  "config",
		Usage: "add config description",
	}

	HomeDirFlag = common.DirectoryFlag{
		Name:  "homedir",
		Usage: "Home directory for the datadir logdir and keystore",
	}

	PprofFlag = cli.StringFlag{
		Name:  "pprof",
		Usage: "ppfof for debug performance, --pprof 1",
	}
)
View Source
var (
	ErrNotMatchedService = errors.New("the service added not match service interface")
	ErrConfigiNotFound   = errors.New("specify config file not exist")
	ErrServiceNotFound   = errors.New("Service not found")
)
View Source
var (
	TServiceService = reflect.TypeOf((*Service)(nil)).Elem()
	TOrService      = reflect.TypeOf((*OrService)(nil)).Elem()
)
View Source
var (
	CommandHelpTemplate = `` /* 471-byte string literal not displayed */

)

Functions

func GetServiceTag

func GetServiceTag(field reflect.StructField) string

GetServiceTag read service tag name to match service that has added in

Types

type API

type API struct {
	Namespace string      // namespace under which the rpc methods of Service are exposed
	Version   string      // api version for DApp's
	Service   interface{} // receiver instance which holds the methods
	Public    bool        // indication if the methods must be considered safe for public use
}

API describes the set of methods offered over the RPC interface

type CommonConfig

type CommonConfig struct {
	HomeDir    string `json:"homeDir,omitempty"`
	ConfigFile string `json:"configFile,omitempty"`
}

CommonConfig read before app run,this fuction shared by other moudles

type DrepApp

type DrepApp struct {
	Context *ExecuteContext
	*cli.App
	// contains filtered or unexported fields
}

DrepApp based on the cli.App, the module service operation is encapsulated. The purpose is to achieve the independence of each module and reduce dependencies as far as possible.

func NewApp

func NewApp() *DrepApp

NewApp create a new app

func (DrepApp) IncludeServices

func (mApp DrepApp) IncludeServices(serviceInstances ...interface{}) error

AddServiceType add many services

func (*DrepApp) Option

func (mApp *DrepApp) Option(option func())

Init do something before app run

func (*DrepApp) Run

func (mApp *DrepApp) Run() error

TODO need a more graceful command supporter Run read the global configuration, parse the global command parameters, initialize the main process one by one, and execute the service before the main process starts.

type ExecuteContext

type ExecuteContext struct {
	ConfigPath   string
	CommonConfig *CommonConfig //
	PhaseConfig  map[string]json.RawMessage
	Cli          *cli.Context
	LifeBus      EventBus.Bus
	Services     []Service

	GitCommit string
	Usage     string
	Quit      chan struct{}
}

ExecuteContext centralizes all the data and global parameters of application execution, and each service can read the part it needs.

func (*ExecuteContext) AggerateFlags

func (econtext *ExecuteContext) AggerateFlags() ([]cli.Command, []cli.Flag)

GetFlags aggregate command configuration items required for each service

func (*ExecuteContext) FlatConfig

func (econtext *ExecuteContext) FlatConfig(phaseName string) error

func (*ExecuteContext) GetApis

func (econtext *ExecuteContext) GetApis() []API

GetApis aggregate interface functions for each service to provide for use by RPC services

func (*ExecuteContext) GetConfig

func (econtext *ExecuteContext) GetConfig(phaseName string) json.RawMessage

GetConfig Configuration is divided into several segments, each service only needs to obtain its own configuration data, and the parsing process is also controlled by each service itself.

func (*ExecuteContext) GetService

func (econtext *ExecuteContext) GetService(name string) Service

GetService In addition, there is a dependency relationship between services. This method is used to find the dependency services you need in the context.

func (*ExecuteContext) RequireService

func (econtext *ExecuteContext) RequireService(name string) Service

RequireService When a service depends on another service, RequireService is used to obtain the dependent service.

func (*ExecuteContext) UnmashalConfig

func (econtext *ExecuteContext) UnmashalConfig(serviceName string, config interface{}) error

type Option

type Option func()

type OrService

type OrService interface {
	Service
	SelectService() Service
}

type Service

type Service interface {
	Name() string                              // service  name must be unique
	Api() []API                                // Interfaces required for services
	CommandFlags() ([]cli.Command, []cli.Flag) // flags required for services
	//P2pMessages() map[int]interface{}
	//Receive(context actor.Context)
	Init(executeContext *ExecuteContext) error
	Start(executeContext *ExecuteContext) error
	Stop(executeContext *ExecuteContext) error
}

Services can customize their own configuration, command parameters, interfaces, services

Jump to

Keyboard shortcuts

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