config

package
v0.0.0-...-0236cb5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTableOperations = 5
)

Variables

This section is empty.

Functions

func Bind

func Bind(v *viper.Viper)

func SetDefaults

func SetDefaults(v *viper.Viper)

SetDefaults takes a viper instance and sets default configuration values

Types

type Column

type Column struct {
	Name      string     `mapstructure:"name"`
	Type      *string    `mapstructure:"type"`
	Generator *Generator `mapstructure:"generator"`
}

func (*Column) Validate

func (c *Column) Validate() error

type Config

type Config struct {
	Project          string        `mapstructure:"project" yaml:"project"`
	Instance         string        `mapstructure:"instance" yaml:"instance"`
	Database         string        `mapstructure:"database" yaml:"database"`
	Threads          int           `mapstructure:"threads" yaml:"threads"`
	NumConns         int           `mapstructure:"num_conns" yaml:"num_cons"`
	MaxExecutionTime time.Duration `mapstructure:"max_execution_time" yaml:"max_execution_time"`
	Operations       Operations    `mapstructure:"operations" yaml:"operations"`
	Pool             Pool          `mapstructure:"pool" yaml:"pool"`
	Tables           []Table       `mapstructure:"tables" yaml:"tables"`
	Batch            bool          `mapstructure:"batch"`
	BatchSize        int           `mapstructure:"batch_size"`
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(v *viper.Viper) (*Config, error)

NewConfig will unmarshal a viper instance into *Config and validate it

func (*Config) Client

func (c *Config) Client(ctx context.Context) (*spanner.Client, error)

Client returns a configured spanner client

func (*Config) Context

func (c *Config) Context() (context.Context, context.CancelFunc)

func (*Config) DB

func (c *Config) DB() string

DB returns the database DSN

func (*Config) Table

func (c *Config) Table(name string) *Table

func (*Config) Validate

func (c *Config) Validate() error

Validate will ensure the configuration is valid for attempting to establish a connection

type GCSBConfig

type GCSBConfig struct {
	Database string             `yaml:"database"`
	Project  string             `yaml:"project"`
	Instance string             `yaml:"instance"`
	Tables   []TableConfigTable `yaml:"tables"`
}

func NewGCSBConfigFromPath

func NewGCSBConfigFromPath(configPath string) (*GCSBConfig, error)

func (*GCSBConfig) DBName

func (c *GCSBConfig) DBName() string

func (*GCSBConfig) GetCreateStatements

func (c *GCSBConfig) GetCreateStatements() []string

func (*GCSBConfig) ParentName

func (c *GCSBConfig) ParentName() string

func (*GCSBConfig) ReadConfig

func (c *GCSBConfig) ReadConfig(configPath string) error

type Generator

type Generator struct {
	Type         *string  `mapstructure:"type"`
	Length       *int     `mapstructure:"length"`
	PrefixLength *int     `mapstructure:"prefix_length" yaml:"prefix_length"`
	Seed         *int64   `mapstructure:"seed"`
	Range        []*Range `mapstructure:"range"`
}

func (*Generator) Validate

func (g *Generator) Validate() error

type Operations

type Operations struct {
	Total       int           `mapstructure:"total" yaml:"total"`
	Read        int           `mapstructure:"read" yaml:"read"`
	Write       int           `mapstructure:"write" yaml:"write"`
	SampleSize  float64       `mapstructure:"sample_size" yaml:"sample_size"`
	ReadStale   bool          `mapstructure:"read_stale" yaml:"read_stale"`
	Staleness   time.Duration `mapstructure:"staleness" yaml:"staleness"`
	PartialKeys bool          `mapstructure:"partial_keys" yaml:"partial_keys"`
}

func (*Operations) Validate

func (o *Operations) Validate() error

type Pool

type Pool struct {
	MaxOpened           int           `mapstructure:"max_opened" yaml:"max_opened"`
	MinOpened           int           `mapstructure:"min_opened" yaml:"min_opened"`
	MaxIdle             int           `mapstructure:"max_idle" yaml:"max_idle"`
	WriteSessions       float64       `mapstructure:"write_sessions" yaml:"write_sessions"`
	HealthcheckWorkers  int           `mapstructure:"healthcheck_workers" yaml:"healthcheck_workers"`
	HealthcheckInterval time.Duration `mapstructure:"healthcheck_interval" yaml:"healthcheck_interval"`
	TrackSessionHandles bool          `mapstructure:"track_session_handles" yaml:"track_session_handles"`
}

func (*Pool) Validate

func (c *Pool) Validate() error

type Range

type Range struct {
	Begin   *interface{} `mapstructure:"begin"`   // Begin for ranges like ranged string & date
	End     *interface{} `mapstructure:"end"`     // End of ranges like ranged string & date
	Length  *int         `mapstructure:"length"`  // Length for generators like string or bytes
	Static  *bool        `mapstructure:"static"`  // Static value indicator for bool generator
	Value   *interface{} `mapstructure:"value"`   // Value for static generation
	Minimum *interface{} `mapstructure:"minimum"` // Minimum for numeric generators
	Maximum *interface{} `mapstructure:"maximum"` // Maximum for numeric generators
}

func (*Range) Validate

func (r *Range) Validate() error

type Table

type Table struct {
	Name       string           `mapstructure:"name"`
	Operations *TableOperations `mapstructure:"operations" yaml:"operations"`
	Columns    []Column         `mapstructure:"columns"`
}

func (*Table) Column

func (t *Table) Column(name string) *Column

func (*Table) Validate

func (t *Table) Validate() error

type TableConfigColumn

type TableConfigColumn struct {
	Name      string               `yaml:"name"`
	Type      string               `yaml:"type"`
	Generator TableConfigGenerator `yaml:"generator"`
}

type TableConfigGenerator

type TableConfigGenerator struct {
	Type         string                    `yaml:"type"`
	Length       int                       `yaml:"length"`
	PrefixLength int                       `yaml:"prefix_length"`
	Threads      int                       `yaml:"threads"`
	KeyRange     TableConfigGeneratorRange `yaml:"key_range"`
	Range        bool                      `yaml:"range"`
	Min          int                       `yaml:"min"`
	Max          int                       `yaml:"max"`
}

type TableConfigGeneratorRange

type TableConfigGeneratorRange struct {
	Start string `yaml:"start"`
	End   string `yaml:"end"`
}

type TableConfigOperations

type TableConfigOperations struct {
	Read  uint `yaml:"read"`
	Write uint `yaml:"write"`
}

type TableConfigTable

type TableConfigTable struct {
	Name       string                `yaml:"name"`
	RowCount   int                   `yaml:"row_count"`
	Columns    []TableConfigColumn   `yaml:"columns"`
	Operations TableConfigOperations `yaml:"operations"`
	PrimaryKey string                `yaml:"primary_key"`
}

func (*TableConfigTable) GetColumnNamesString

func (c *TableConfigTable) GetColumnNamesString() string

func (*TableConfigTable) GetCreateStatement

func (c *TableConfigTable) GetCreateStatement() string

type TableOperations

type TableOperations struct {
	// Read  int `mapstructure:"read"`
	// Write int `mapstructure:"write"`
	Total int `mapstructure:"total"`
}

type Validate

type Validate interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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