options

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 10 Imported by: 1

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

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

func PathToSlice(path string) []string

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 Cloudflare struct {
	Enabled     bool   `yaml:"enabled"`
	AccountID   string `yaml:"accountId"`
	ApiToken    string `yaml:"apiToken"`
	BucketScope string `yaml:"bucketScope"`
	BucketName  string `yaml:"bucketName"`
	DatasetPath string `yaml:"datasetPath"`
}

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 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.

func (Dialect) GetAddrs

func (d Dialect) GetAddrs() []string

func (Dialect) GetPorts

func (d Dialect) GetPorts() []string

type GraphQL

type GraphQL struct {
	Transports []string     `yaml:"transports"`
	Addr       string       `yaml:"addr"`
	Cors       Cors         `yaml:"cors"`
	Cache      GraphQLCache `yaml:"cache"`
}

func (*GraphQL) TransportEnabled

func (g *GraphQL) TransportEnabled(t string) bool

type GraphQLCache

type GraphQLCache struct {
	Adapter            string        `yaml:"adapter"`
	QueryCacheDuration time.Duration `yaml:"queryCacheDuration"`
}

type Indexer

type Indexer struct {
	Subscribers []Subscriber `yaml:"subscribers"`
}

func (*Indexer) GetByType

func (s *Indexer) GetByType(t string) (*Subscriber, error)

type Ipfs

type Ipfs struct {
	Enabled bool   `yaml:"enabled"`
	Addr    string `yaml:"addr"`
}

type Labels

type Labels struct {
	DataPath string `yaml:"path"`
}

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 Nats struct {
	Enabled bool    `yaml:"enabled"`
	Addr    string  `yaml:"addr"`
	Queues  []Queue `yaml:"queues"`
}

func (*Nats) GetQueueByName

func (n *Nats) GetQueueByName(name string) (*Queue, bool)

type Network

type Network struct {
	Name          string `yaml:"name"`
	NetworkId     int    `yaml:"networkId"`
	CanonicalName string `yaml:"canonicalName"`
	Symbol        string `yaml:"symbol"`
	Website       string `yaml:"website"`
	Suspended     bool   `yaml:"suspended"`
	Maintenance   bool   `yaml:"maintenance"`
}

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.
	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

func NewDefaultOptions(paths []string, skipFlags bool) (*Options, error)

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

func (o *Options) DeleteModule(name string) error

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

func (o *Options) GetDbDialect(d string) (*Dialect, error)

GetDbDialect returns the database dialect configuration.

func (*Options) GetNetworkById

func (o *Options) GetNetworkById(id uint64) (*Network, error)

func (*Options) GetPprofByServiceTag

func (o *Options) GetPprofByServiceTag(service string) (*Pprof, error)

func (*Options) GetSqliteDbPath

func (o *Options) GetSqliteDbPath() string

GetSqliteDbPath returns the SQLite database path.

func (*Options) GetStatsByServiceTag

func (o *Options) GetStatsByServiceTag(service string) (*Prometheus, error)

func (*Options) ListModules

func (o *Options) ListModules() []string

ListModules returns a list of all module names currently configured. This can be used to inspect which modules are loaded.

func (*Options) Validate

func (o *Options) Validate() error

Validate goes through the validation of the provided options @TODO: Fix this in the future...

type Pprof

type Pprof struct {
	Name    string `yaml:"name"`
	Enabled bool   `yaml:"enabled"`
	Addr    string `yaml:"addr"`
}

type Prometheus

type Prometheus struct {
	Name    string `yaml:"name"`
	Enabled bool   `yaml:"enabled"`
	Addr    string `yaml:"addr"`
}

type Queue

type Queue struct {
	Name          string `yaml:"name"`
	Subject       string `yaml:"subject"`
	DeliveryGroup string `yaml:"deliveryGroup"`
}

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

func (r *Rpc) TransportEnabled(transportName string) bool

type Solc

type Solc struct {
	Enabled           bool          `yaml:"enabled"`
	SyncEvery         time.Duration `yaml:"syncEvery"`
	ReleasesPath      string        `yaml:"releasesPath"`
	HttpClientTimeout time.Duration `yaml:"httpClientTimeout"`
}

type Sourcify

type Sourcify struct {
	Enabled           bool          `yaml:"enabled"`
	Endpoint          string        `yaml:"endpoint"`
	MaxRetry          int           `yaml:"maxRetry"`
	RetryDelay        time.Duration `yaml:"retryDelay"`
	RateLimit         int           `yaml:"rateLimit"`
	RateLimitDuration time.Duration `yaml:"rateLimitDuration"`
}

type Storage

type Storage struct {
	Enabled       bool   `yaml:"enabled" json:"enabled"`
	ContractsPath string `yaml:"contractsPath" json:"contractsPath"`
	DatabasePath  string `yaml:"databasePath" json:"databasePath"`
}

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

type Unpacker

type Unpacker struct {
	ForceReprocess bool `yaml:"forceReprocess"` // Reprocess all the contracts regardless of their local state
	OtsEnabled     bool `yaml:"otsEnabled"`
}

Jump to

Keyboard shortcuts

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