Documentation ¶
Overview ¶
Package options provides functionality for managing application configuration options. It supports loading configuration from various sources like YAML files and environment variables.
The package defines the Options struct, which holds all the configuration settings, and provides functions to load these settings from different sources.
Index ¶
- func GetModule[T ModuleConfig](name string) (T, bool)
- func PathToSlice(path string) []string
- func SetGlobalOptions(opt *Options)
- type Cache
- type Cloudflare
- type Cors
- type Db
- type GraphQL
- type GraphQLCache
- type Ipfs
- type Logger
- type ModuleConfig
- type Nats
- type Network
- type Options
- func (o *Options) AddModule(name string, config ModuleConfig) error
- func (o *Options) DeleteModule(name string) error
- func (o *Options) GetNetworkById(id uint64) (*Network, error)
- func (o *Options) GetPprofByServiceTag(service string) (*Pprof, error)
- func (o *Options) GetSqliteDbPath() string
- func (o *Options) GetStatsByServiceTag(service string) (*Prometheus, error)
- func (o *Options) ListModules() []string
- func (o *Options) Validate() error
- type Pprof
- type Prometheus
- type Queue
- type Rpc
- type Storage
- type Subscriber
- type Syncer
- type Unpacker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetModule ¶
func GetModule[T ModuleConfig](name string) (T, bool)
GetModule retrieves the configuration for a module by its name using the global Options instance. It is a generic function that allows specifying the type of the configuration expected. The function returns the requested module configuration and a boolean indicating if the module was found.
func PathToSlice ¶
PathToSlice converts a comma-separated string of paths into a slice of strings. Each path is trimmed of any leading and trailing whitespace characters.
func SetGlobalOptions ¶
func SetGlobalOptions(opt *Options)
SetGlobalOptions sets the provided Options object as the global options. This function is usually called after initializing the options to make them accessible throughout the application.
Types ¶
type Cache ¶
type Cache struct { Addr string `yaml:"addr" json:"addr"` Password string `yaml:"password" json:"password"` DB int `yaml:"db" json:"db"` MaxRetries int `yaml:"maxRetries" json:"maxRetries"` MinRetryBackoff time.Duration `yaml:"minRetryBackoff" json:"minRetryBackoff"` MaxRetryBackoff time.Duration `yaml:"maxRetryBackoff" json:"maxRetryBackoff"` DialTimeout time.Duration `yaml:"dialTimeout" json:"dialTimeout"` ReadTimeout time.Duration `yaml:"readTimeout" json:"readTimeout"` WriteTimeout time.Duration `yaml:"writeTimeout" json:"writeTimeout"` }
type Cloudflare ¶
type Cors ¶
type Cors struct { Debug bool `yaml:"debug"` MaxAge int `yaml:"maxAge"` AllowCredentials bool `yaml:"allowCredentials"` OptionsPassthrough bool `yaml:"optionsPassthrough"` AllowedOrigins []string `yaml:"allowedOrigins"` AllowedMethods []string `yaml:"allowedMethods"` AllowedHeaders []string `yaml:"allowedHeaders"` ExposedHeaders []string `yaml:"exposedHeaders"` }
type GraphQL ¶
type GraphQL struct { Transports []string `yaml:"transports"` Addr string `yaml:"addr"` Cors Cors `yaml:"cors"` Cache GraphQLCache `yaml:"cache"` }
func (*GraphQL) TransportEnabled ¶
type GraphQLCache ¶
type Logger ¶
type Logger struct { Env string `yaml:"env" json:"env"` // Env specifies the environment (e.g., "production", "development"). Level string `yaml:"level" json:"level"` // Level defines the logging level (e.g., "info", "debug"). }
Logger defines the configuration for logging. It includes environment and logging level settings.
type ModuleConfig ¶
type ModuleConfig interface {
Validate() error // Example validation method
}
ModuleConfig is an interface for module configurations.
type Nats ¶
type Options ¶
type Options struct { OptionsPath string `default:"~/.unpack/inspector/options.yaml" env:"INSPECTOR_OPTIONS_PATH"` // OptionsPath defines the path to the configuration file. Logger Logger `yaml:"logger" json:"logger"` // Logger specifies the configuration settings for logging. Networks []Network `yaml:"networks" json:"networks"` // Networks lists all the network configurations. *clients.Options `yaml:"nodes"` // Options embeds the client options related to node configurations. Db Db // Db configures the database settings. Nats Nats // Nats defines the configuration for NATS client and its queues. Storage Storage // Storage specifies the settings for storage mechanisms. Cache Cache // Cache outlines the configurations for caching, typically with redis. Etherscan *etherscan.Options // Etherscan holds options for interacting with the Etherscan API. Syncer Syncer `yaml:"syncer"` // Syncer configures the synchronization options. Unpacker Unpacker `yaml:"unpacker"` // Unpacker details the settings for unpacking and processing data. Graphql GraphQL `yaml:"graphql"` // Graphql configures the GraphQL server settings. Pprof []Pprof `yaml:"pprof"` // Pprof includes settings for profiling the application. Stats []Prometheus `yaml:"stats"` // Stats contains configurations for Prometheus metrics. Ipfs Ipfs `yaml:"ipfs"` // Ipfs configures the IPFS node settings. Rpc Rpc `yaml:"rpc"` // Rpc configures the RPC server settings. Cloudflare Cloudflare `yaml:"cloudflare"` // Cloudflare holds configurations specific to Cloudflare integrations. Modules map[string]ModuleConfig // Modules holds configuration settings for various modular components of the application. }
Options contains all the configuration options for the inspector services.
func G ¶
func G() *Options
G returns the global Options object set by SetGlobalOptions. It provides a convenient way to access application-wide configurations.
func NewDefaultOptions ¶
NewDefaultOptions creates a new Options object with the given configuration paths. It loads the configuration from the specified paths and handles any errors encountered during the loading process. Returns an error if loading fails.
func (*Options) AddModule ¶
func (o *Options) AddModule(name string, config ModuleConfig) error
AddModule adds a new module configuration to the Options struct. The name parameter is a unique identifier for the module, and config is the ModuleConfig to be added. It returns an error if the module already exists or the configuration is invalid.
func (*Options) DeleteModule ¶
DeleteModule removes a module configuration from the Options. The name parameter specifies the module to be removed. It returns an error if the module cannot be found.
func (*Options) GetPprofByServiceTag ¶
func (*Options) GetSqliteDbPath ¶
func (*Options) GetStatsByServiceTag ¶
func (o *Options) GetStatsByServiceTag(service string) (*Prometheus, error)
func (*Options) ListModules ¶
ListModules returns a list of all module names currently configured. This can be used to inspect which modules are loaded.
type Prometheus ¶
type Rpc ¶
type Rpc struct { Enabled bool `yaml:"enabled"` Addr string `yaml:"addr"` ExposeSmd bool `yaml:"exposeSmd"` AllowCORS bool `yaml:"allowCORS"` DisableTransportChecks bool `yaml:"disableTransportChecks"` Transports []string `yaml:"transports"` Docs bool `yaml:"docs"` DocsTitle string `yaml:"docsTitle"` }
func (*Rpc) TransportEnabled ¶
type Subscriber ¶
type Subscriber struct { Enabled bool `yaml:"enabled"` SubjectName string `yaml:"subjectName"` Network string `yaml:"network"` Resumption bool `yaml:"resumption"` Type string `yaml:"type"` StartBlockNumber int `yaml:"startBlockNumber"` EndBlockNumber int `yaml:"endBlockNumber"` }
func (*Subscriber) Validate ¶
func (s *Subscriber) Validate() error
type Syncer ¶
type Syncer struct {
Subscribers []Subscriber `yaml:"subscribers"`
}