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 Contact
- type Cors
- type Db
- type Dialect
- type GraphQL
- type GraphQLCache
- type Indexer
- type Ipfs
- type Labels
- type License
- type Logger
- type ModuleConfig
- type Nats
- type Network
- type OpenAPI
- type Options
- func (o *Options) AddModule(name string, config ModuleConfig) error
- func (o *Options) DeleteModule(name string) error
- func (o *Options) GetDbDialect(d string) (*Dialect, 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 Rest
- type Rpc
- type Server
- type Solc
- type Sourcify
- type Storage
- type Subscriber
- 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 Contact ¶ added in v0.9.7
type Contact struct { // Name is the name of the contact person or organization. Name string `yaml:"name"` // URL is the URL to the contact information or support page. URL string `yaml:"url"` // Email is the email address of the contact person or organization. Email string `yaml:"email"` }
Contact holds the contact information for API support. This includes the name of the contact person or organization, the URL to contact them, and their email address.
type Cors ¶
type Cors struct { Enabled bool `yaml:"enabled"` 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 Db ¶
type Db struct {
Dialects []Dialect `yaml:"dialects"`
}
Db represents a collection of database dialects.
type Dialect ¶
type Dialect struct { Name string `yaml:"name"` Enabled bool `yaml:"enabled"` Datasource string `yaml:"datasource"` // Sqlite related configuration MigrationDir string `yaml:"migrationDir"` // Sqlite related configuration Endpoints []string `yaml:"endpoints"` // Clickhouse related configuration Username string `yaml:"username"` // Clickhouse related configuration Password string `yaml:"password"` // Clickhouse related configuration Database string `yaml:"database"` // Clickhouse and Sqlite related configuration Tls bool `yaml:"tls"` Insecure bool `yaml:"insecure"` // Clickhouse related configuration Compression string `yaml:"compression"` // Clickhouse related configuration DialTimeout string `yaml:"dialTimeout"` MaxIdleConnections int `yaml:"maxIdleConnections"` // Clickhouse and Sqlite related configuration MaxOpenConnections int `yaml:"maxOpenConnections"` // Clickhouse and Sqlite related configuration ConnectionMaxLifetime string `yaml:"connectionMaxLifetime"` // Clickhouse and Sqlite related configuration }
Dialect represents a database dialect configuration.
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 Indexer ¶
type Indexer struct {
Subscribers []Subscriber `yaml:"subscribers"`
}
type License ¶ added in v0.9.7
type License struct { // Name is the name of the license. Name string `yaml:"name"` // URL is the URL to the full license text. URL string `yaml:"url"` }
License holds the licensing information for the API. This includes the name of the license and a URL to the full license text.
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 OpenAPI ¶ added in v0.9.7
type OpenAPI struct { // Title is the title of the API. Title string `yaml:"title"` // Description is the description of the API Description string `yaml:"description"` // Version is the version of the API. Version string `yaml:"version"` // Terms is the URL to the terms of service for the API. Terms string `yaml:"terms"` // Contact holds the contact information for API support. Contact Contact `yaml:"contact"` // License holds the licensing information for the API. License License `yaml:"license"` // Servers is a list of server configurations where the API can be accessed. Servers []Server `yaml:"servers"` }
OpenAPI holds metadata and configuration details for the OpenAPI documentation of the API. This includes the API title, version, terms of service URL, contact information, licensing information, and server configurations.
type Options ¶
type Options struct { OptionsPath string `default:"~/.unpack/inspector/options.yaml" env:"UNPACK_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 *clients.Options `yaml:"blockchain"` Db Db // Db configure 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. Indexer Indexer `yaml:"indexer"` // Indexer 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. Rest Rest `yaml:"rest"` // Rest configures the REST API server settings. Cloudflare Cloudflare `yaml:"cloudflare"` // Cloudflare holds configurations specific to Cloudflare integrations. Sourcify Sourcify `yaml:"sourcify"` Labels Labels `yaml:"labels"` Solc Solc `yaml:"solc"` 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) GetDbDialect ¶
GetDbDialect returns the database dialect configuration.
func (*Options) GetPprofByServiceTag ¶
func (*Options) GetSqliteDbPath ¶
GetSqliteDbPath returns the SQLite database path.
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 Rest ¶ added in v0.9.7
type Rest struct { // Enabled indicates whether the REST API is enabled. Enabled bool `yaml:"enabled"` // Addr is the address that the REST API should bind to. Addr string `yaml:"addr"` // RenderHiddenOperations if enabled will display hidden operations in rendered openapi.(json|yaml) RenderHiddenOperations bool `yaml:"renderHiddenOperations"` // OpenAPI holds the OpenAPI documentation details for the API. OpenAPI OpenAPI `yaml:"openapi"` // Cors holds the CORS details for the API. Cors Cors `yaml:"cors"` // Namespaces is a list of namespaces that the API will serve. Namespaces []string `yaml:"namespaces"` }
Rest holds the configuration for the REST API. This includes whether the REST API is enabled, the address it should bind to, OpenAPI documentation details, and a list of namespaces that the API will serve.
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"` Namespaces []string `yaml:"namespaces"` Transports []string `yaml:"transports"` Docs bool `yaml:"docs"` DocsTitle string `yaml:"docsTitle"` }
func (*Rpc) TransportEnabled ¶
type Server ¶ added in v0.9.7
type Server struct { // Description is a brief description of the server. Description string `yaml:"description"` // Enabled indicates whether this server configuration is enabled. Enabled bool `yaml:"enabled"` // URL is the URL where the API can be accessed on this server. Url string `yaml:"url"` }
Server represents a server configuration where the API can be accessed. This includes a description of the server, whether it is enabled, and its URL.
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"` WorkersCount int `yaml:"workersCount"` ChannelBufferSize int `yaml:"channelBufferSize"` StartBlockNumber int `yaml:"startBlockNumber"` EndBlockNumber int `yaml:"endBlockNumber"` }
func (*Subscriber) Validate ¶
func (s *Subscriber) Validate() error