serverv2

package module
v2.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 22 Imported by: 7

Documentation

Overview

Package serverv2 defines constants for server configuration flags and output formats.

Index

Constants

View Source
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

View Source
var (
	FlagMinGasPrices       = prefix("minimum-gas-prices")
	FlagCPUProfiling       = prefix("cpu-profile")
	FlagUnsafeSkipUpgrades = prefix("unsafe-skip-upgrades")
)

Functions

func GetLoggerFromCmd

func GetLoggerFromCmd(cmd *cobra.Command) log.Logger

GetLoggerFromCmd returns the logger instance from the command context.

func GetLoggerFromContext

func GetLoggerFromContext(ctx context.Context) log.Logger

GetLoggerFromContext returns the logger instance from the context.

func GetViperFromCmd

func GetViperFromCmd(cmd *cobra.Command) *viper.Viper

GetViperFromCmd returns the viper instance from the command context.

func GetViperFromContext

func GetViperFromContext(ctx context.Context) *viper.Viper

GetViperFromContext returns the viper instance from the context.

func IsAppRequired

func IsAppRequired(cmd *cobra.Command, required ...[]string) bool

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

func NewLogger(cfg server.ConfigMap, out io.Writer) (log.Logger, error)

NewLogger creates the default SDK logger. It reads the log level and format from the server context.

func ReadConfig

func ReadConfig(configPath string) (*viper.Viper, error)

ReadConfig returns a viper instance of the config file

func SetCmdServerContext

func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger)

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

func SetServerContext(ctx context.Context, viper *viper.Viper, logger log.Logger) context.Context

SetServerContext sets the logger and viper in the context. The server manager expects the logger and viper to be set in the context.

func UnmarshalSubConfig

func UnmarshalSubConfig(cfg map[string]any, subName string, target any) error

UnmarshalSubConfig unmarshals the given (sub) config from the main config (given as a map) into the target. If subName is empty, the main config is unmarshaled into the target.

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

type ConfigWriter interface {
	WriteConfig(path string) error
}

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

func (s *Server[T]) CLICommands() CLIConfig

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]) Configs

func (s *Server[T]) Configs() map[string]any

Configs returns all configs of all server components.

func (*Server[T]) Name

func (s *Server[T]) Name() string

func (*Server[T]) Start

func (s *Server[T]) Start(ctx context.Context) error

Start starts all components concurrently.

func (*Server[T]) StartCmdFlags

func (s *Server[T]) StartCmdFlags() *pflag.FlagSet

func (*Server[T]) StartFlags

func (s *Server[T]) StartFlags() []*pflag.FlagSet

StartFlags returns all flags of all server components.

func (*Server[T]) Stop

func (s *Server[T]) Stop(ctx context.Context) error

Stop stops all server components synchronously.

func (*Server[T]) WriteConfig

func (s *Server[T]) WriteConfig(configPath string) error

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

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.

Jump to

Keyboard shortcuts

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