options

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 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 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.

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

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

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

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 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"`
	LibrariesPath string `yaml:"librariesPath" json:"librariesPath"`
}

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