models

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySQLDriver    = "mysql"
	PostgresDriver = "postgres"
	SQLiteDriver   = "sqlite3"
	MSSQLDriver    = "mssql"
)
View Source
const (
	Append  DatasetType = "append"
	Replace DatasetType = "replace"

	NumberType     FieldType = "number"
	DateType       FieldType = "date"
	DatetimeType   FieldType = "datetime"
	MoneyType      FieldType = "money"
	PercentageType FieldType = "percentage"
	StringType     FieldType = "string"
	DurationType   FieldType = "duration"
)

Variables

Functions

This section is empty.

Types

type Config

type Config struct {
	GeckoboardAPIKey string          `yaml:"geckoboard_api_key"`
	DatabaseConfig   *DatabaseConfig `yaml:"database"`
	RefreshTimeSec   uint16          `yaml:"refresh_time_sec"`
	Datasets         []Dataset       `yaml:"datasets"`
}

func LoadConfig

func LoadConfig(filepath string) (config *Config, err error)

func (Config) Validate

func (c Config) Validate() (errors []string)

type DatabaseConfig

type DatabaseConfig struct {
	Driver    string            `yaml:"driver"`
	URL       string            `yaml:"-"`
	Host      string            `yaml:"host"`
	Port      string            `yaml:"port"`
	Protocol  string            `yaml:"protocol"`
	Database  string            `yaml:"name"`
	Username  string            `yaml:"username"`
	Password  string            `yaml:"password"`
	TLSConfig *TLSConfig        `yaml:"tls_config"`
	Params    map[string]string `yaml:"params"`
}

DatabaseConfig holds the db type, url and other custom options such as tls config

func (DatabaseConfig) Validate

func (dc DatabaseConfig) Validate() (errors []string)

type Dataset

type Dataset struct {
	Name         string           `json:"id"                   yaml:"name"`
	UpdateType   DatasetType      `json:"-"                    yaml:"update_type"`
	UniqueBy     []string         `json:"unique_by,omitempty"  yaml:"unique_by,omitempty"`
	SQL          string           `json:"-"                    yaml:"sql"`
	Fields       []Field          `json:"-"                    yaml:"fields"`
	SchemaFields map[string]Field `json:"fields"               yaml:"-"`
}

func (Dataset) BuildDataset

func (ds Dataset) BuildDataset(dc *DatabaseConfig, db *sql.DB) (DatasetRows, error)

BuildDataset calls queryDatasource to query the datasource for a dataset entry and builds up a slice of rows ready for processing by the client

func (*Dataset) BuildSchemaFields

func (ds *Dataset) BuildSchemaFields() error

BuildSchemaFields creates a map[string]Field of the dataset fields for sending over to Geckoboard

func (Dataset) Validate

func (ds Dataset) Validate() (errors []string)

type DatasetRows

type DatasetRows []map[string]interface{}

DatasetRows holds a slice of map[string]interface{} which is used to send to a geckoboard dataset

type DatasetType

type DatasetType string

type Field

type Field struct {
	Type         FieldType `json:"type"                     yaml:"type"`
	Key          string    `json:"-"                        yaml:"key"`
	Name         string    `json:"name"                     yaml:"name"`
	CurrencyCode string    `json:"currency_code,omitempty"  yaml:"currency_code"`
	TimeUnit     string    `json:"time_unit,omitempty"      yaml:"time_unit"`
	Optional     bool      `json:"optional,omitempty"       yaml:"optional,omitempty"`
}

func (Field) KeyValue

func (f Field) KeyValue() string

KeyValue returns the field key if present otherwise by default returns the field name underscored

func (Field) Validate

func (f Field) Validate() (errors []string)

type FieldType

type FieldType string

type Number

type Number struct {
	Int64   int64
	Float32 float32
	Float64 float64

	Type string
}

func (*Number) Scan

func (n *Number) Scan(value interface{}) error

func (*Number) Value

func (n *Number) Value(optional bool) interface{}

type TLSConfig

type TLSConfig struct {
	KeyFile  string `yaml:"key_file"`
	CertFile string `yaml:"cert_file"`
	CAFile   string `yaml:"ca_file"`
	SSLMode  string `yaml:"ssl_mode"`
}

Jump to

Keyboard shortcuts

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