options

package
v0.0.0-...-77d485b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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"`
	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 {
	Dialect      string `yaml:"dialect"`
	Datasource   string `yaml:"datasource"`
	MigrationDir string `yaml:"migrationDir"`
}

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 Ipfs

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

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:"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

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

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"`
	Transports             []string `yaml:"transports"`
	Docs                   bool     `yaml:"docs"`
	DocsTitle              string   `yaml:"docsTitle"`
}

func (*Rpc) TransportEnabled

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

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"`
	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"`
}

func (*Syncer) GetByType

func (s *Syncer) GetByType(t string) (*Subscriber, 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