Documentation ¶
Overview ¶
Package serverv2 defines constants for server configuration flags and output formats.
Index ¶
- Constants
- Variables
- func ExternalIP() (string, error)
- func GetLoggerFromCmd(cmd *cobra.Command) log.Logger
- func GetLoggerFromContext(ctx context.Context) log.Logger
- func GetViperFromCmd(cmd *cobra.Command) *viper.Viper
- func GetViperFromContext(ctx context.Context) *viper.Viper
- func IsAppRequired(cmd *cobra.Command, required ...[]string) bool
- func NewLogger(cfg server.ConfigMap, out io.Writer) (log.Logger, error)
- func ReadConfig(configPath string) (*viper.Viper, error)
- func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger)
- func SetServerContext(ctx context.Context, viper *viper.Viper, logger log.Logger) context.Context
- func UnmarshalSubConfig(cfg map[string]any, subName string, target any) error
- type CLIConfig
- type CommandFactory
- type CommandFactoryOption
- func WithConfigWriter(configWriter ConfigWriter) CommandFactoryOption
- func WithDefaultHomeDir(homedir string) CommandFactoryOption
- func WithEnvPrefix(envPrefix string) CommandFactoryOption
- func WithLoggerFactory(loggerFactory func(server.ConfigMap, io.Writer) (log.Logger, error)) CommandFactoryOption
- func WithStdDefaultHomeDir(defaultHomeBasename string) CommandFactoryOption
- type ConfigWriter
- type HasCLICommands
- type HasConfig
- type HasStartFlags
- type Server
- func (s *Server[T]) CLICommands() CLIConfig
- func (s *Server[T]) Config() ServerConfig
- func (s *Server[T]) Configs() map[string]any
- func (s *Server[T]) Name() string
- func (s *Server[T]) Start(ctx context.Context) error
- func (s *Server[T]) StartCmdFlags() *pflag.FlagSet
- func (s *Server[T]) StartFlags() []*pflag.FlagSet
- func (s *Server[T]) Stop(ctx context.Context) error
- func (s *Server[T]) WriteConfig(configPath string) error
- type ServerComponent
- type ServerConfig
Constants ¶
const ( // FlagHome specifies the home directory flag. FlagHome = "home" FlagLogLevel = "log_level" // Sets the logging level FlagLogFormat = "log_format" // Specifies the log output format FlagLogNoColor = "log_no_color" // Disables colored log output FlagTrace = "trace" // Enables trace-level logging // OutputFormatJSON defines the JSON output format option. OutputFormatJSON = "json" )
Variables ¶
var ( FlagMinGasPrices = prefix("minimum-gas-prices") FlagCPUProfiling = prefix("cpu-profile") FlagUnsafeSkipUpgrades = prefix("unsafe-skip-upgrades") )
Functions ¶
func ExternalIP ¶
ExternalIP https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go
func GetLoggerFromCmd ¶
GetLoggerFromCmd returns the logger instance from the command context.
func GetLoggerFromContext ¶
GetLoggerFromContext returns the logger instance from the context.
func GetViperFromCmd ¶
GetViperFromCmd returns the viper instance from the command context.
func GetViperFromContext ¶
GetViperFromContext returns the viper instance from the context.
func IsAppRequired ¶
IsAppRequired determines if a command requires a full application to be built by recursively checking the command hierarchy against known command paths.
The function works by: 1. Combining default appBuildingCommands with additional required commands 2. Building command paths by traversing up the command tree 3. Checking if any known command path matches the current command path
Time Complexity: O(d * p) where d is command depth and p is number of paths Space Complexity: O(p) where p is total number of command paths
func NewLogger ¶
NewLogger creates the default SDK logger. It reads the log level and format from the server context.
func ReadConfig ¶
ReadConfig returns a viper instance of the config file
func SetCmdServerContext ¶
SetCmdServerContext sets a command's Context value to the provided argument. The server manager expects the logger and viper to be set in the context. If the context has not been set, set the given context as the default.
func SetServerContext ¶
SetServerContext sets the logger and viper in the context. The server manager expects the logger and viper to be set in the context.
Types ¶
type CLIConfig ¶
type CLIConfig struct { // Commands defines the main command of a server component. Commands []*cobra.Command // Queries defines the query commands of a server component. // Those commands are meant to be added in the root query command. Queries []*cobra.Command // Txs defines the tx commands of a server component. // Those commands are meant to be added in the root tx command. Txs []*cobra.Command }
CLIConfig defines the CLI configuration for a component server.
type CommandFactory ¶
type CommandFactory struct {
// contains filtered or unexported fields
}
CommandFactory is a factory help create server/v2 root commands. For example usage see simapp/v2/cmd/root_di.go
func NewCommandFactory ¶
func NewCommandFactory(opts ...CommandFactoryOption) (*CommandFactory, error)
NewCommandFactory creates a new CommandFactory with the given options.
func (*CommandFactory) EnhanceRootCommand ¶
func (f *CommandFactory) EnhanceRootCommand(cmd *cobra.Command)
EnhanceRootCommand sets the viper and logger in the command context.
func (*CommandFactory) ParseCommand ¶
func (f *CommandFactory) ParseCommand( rootCmd *cobra.Command, args []string, ) (*cobra.Command, server.ConfigMap, log.Logger, error)
ParseCommand parses args against the input rootCmd CLI skeleton then returns the target subcommand, a fully realized config map, and a properly configured logger. If `WithConfigWriter` was set in the factory options, the config writer will be used to write the app.toml file. Internally a viper instance is created and used to bind the flags to the config map. Future invocations of EnhanceCommandContext will set the viper instance and logger in the command context.
type CommandFactoryOption ¶
type CommandFactoryOption func(*CommandFactory) error
func WithConfigWriter ¶
func WithConfigWriter(configWriter ConfigWriter) CommandFactoryOption
WithConfigWriter sets the config writer for the command factory. If set the config writer will be used to write TOML config files during ParseCommand invocations.
func WithDefaultHomeDir ¶
func WithDefaultHomeDir(homedir string) CommandFactoryOption
WithDefaultHomeDir sets the server's default home directory.
func WithEnvPrefix ¶
func WithEnvPrefix(envPrefix string) CommandFactoryOption
WithEnvPrefix sets the environment variable prefix for the command factory.
func WithLoggerFactory ¶
func WithLoggerFactory(loggerFactory func(server.ConfigMap, io.Writer) (log.Logger, error)) CommandFactoryOption
WithLoggerFactory sets the logger factory for the command factory.
func WithStdDefaultHomeDir ¶
func WithStdDefaultHomeDir(defaultHomeBasename string) CommandFactoryOption
WithStdDefaultHomeDir sets the server's default home directory `user home directory`/`defaultHomeBasename`.
type ConfigWriter ¶
ConfigWriter is a server component that can write its config to a file.
func AddCommands ¶
func AddCommands[T transaction.Tx]( rootCmd *cobra.Command, logger log.Logger, appCloser io.Closer, globalAppConfig server.ConfigMap, globalServerConfig ServerConfig, components ...ServerComponent[T], ) (ConfigWriter, error)
AddCommands add the server commands to the root command It configures the config handling and the logger handling
type HasCLICommands ¶
type HasCLICommands interface {
CLICommands() CLIConfig
}
HasCLICommands is a server component that has CLI commands.
type HasConfig ¶
type HasConfig interface {
Config() any
}
HasConfig is a server component that has a config.
type HasStartFlags ¶
type HasStartFlags interface { // StartCmdFlags returns server start flags. // Those flags should be prefixed with the server name. // They are then merged with the server config in one viper instance. StartCmdFlags() *pflag.FlagSet }
HasStartFlags is a server component that has start flags.
type Server ¶
type Server[T transaction.Tx] struct { // contains filtered or unexported fields }
Server is the top-level server component which contains all other server components.
func NewServer ¶
func NewServer[T transaction.Tx]( config ServerConfig, components ...ServerComponent[T], ) *Server[T]
func (*Server[T]) CLICommands ¶
CLICommands returns all CLI commands of all components.
func (*Server[T]) Config ¶
func (s *Server[T]) Config() ServerConfig
Config returns config of the server component
func (*Server[T]) StartCmdFlags ¶
func (*Server[T]) StartFlags ¶
StartFlags returns all flags of all server components.
func (*Server[T]) WriteConfig ¶
WriteConfig writes the config to the given path. Note: it does not use viper.WriteConfigAs because we do not want to store flag values in the config.
type ServerComponent ¶
type ServerComponent[T transaction.Tx] interface { // Name returns the name of the server component. Name() string // Start starts the server component. Start(context.Context) error // Stop stops the server component. // Once Stop has been called on a server component, it may not be reused. Stop(context.Context) error }
ServerComponent is a server component that can be started and stopped.
type ServerConfig ¶
type ServerConfig struct {
MinGasPrices string `` /* 295-byte string literal not displayed */
}
ServerConfig defines configuration for the server component.
func DefaultServerConfig ¶
func DefaultServerConfig() ServerConfig
DefaultServerConfig returns the default config of server component
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
api
|
|
grpc/gogoreflection
Package gogoreflection implements gRPC reflection for gogoproto consumers the normal reflection library does not work as it points to a different singleton registry.
|
Package gogoreflection implements gRPC reflection for gogoproto consumers the normal reflection library does not work as it points to a different singleton registry. |
appmanager
module
|
|
cometbft
module
|
|
stf
module
|
|
Package streaming provides shared data structures and interfaces for communication between the host application and plugins in a streaming context.
|
Package streaming provides shared data structures and interfaces for communication between the host application and plugins in a streaming context. |