app

package
v0.0.0-...-a173fca Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigFileFlag general config file flag
	ConfigFileFlag = cli.StringFlag{
		Name:  "config",
		Usage: "add config description",
	}
	// HomeDirFlag general home directory flag
	HomeDirFlag = common.DirectoryFlag{
		Name:  "homedir",
		Usage: "Home directory for the datadir logdir and keystore",
	}
	// PprofFlag general pprof flag
	PprofFlag = cli.BoolFlag{
		Name:  "pprof",
		Usage: "ppfof for debug performance, --pprof = true",
	}

	TestNetFlag = cli.BoolFlag{
		Name:  "testnet",
		Usage: "start test net,default is mainnet, --testnet = true",
	}
	SoloNetFlag = cli.BoolFlag{
		Name:  "solonet",
		Usage: "start test net,default is mainnet, --testnet = true",
	}
)
View Source
var (
	// ErrNotMatchedService print error msg
	ErrNotMatchedService = errors.New("the service added not match service interface")
	// ErrConfigiNotFound print error msg
	ErrConfigiNotFound = errors.New("specify config file not exist")
	// ErrServiceNotFound print error msg
	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 general template of command
	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

IncludeServices add many services

func (*DrepApp) Option

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

Option init do something before app run

func (*DrepApp) Run

func (mApp *DrepApp) Run() error

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. TODO need a more graceful command supporter

type ExecuteContext

type ExecuteContext struct {
	NetConfigType params.NetType //mainnet testnet solonet
	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)

AggerateFlags aggregate command configuration items required for each service

func (*ExecuteContext) FlatConfig

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

FlatConfig marshal json config to map

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

UnmashalConfig unmashal json config

type Option

type Option func()

Option type definition

type OrService

type OrService interface {
	Service
	SelectService() Service
}

OrService define interface of OrService

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
}

Service 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