Documentation ¶
Index ¶
- Constants
- func ConvertMessageToBigQueryType(t proto.Message) bigquery.ValueSaver
- func QueryableNameFromQualifiedName(qualifiedName string) string
- func SchemaFromFile(fil *os.File) (schema bigquery.Schema, err error)
- type BaseModule
- type BigQuery
- func (bq *BigQuery) CreateTableFromSchema(tableName string, schema bigquery.Schema, table *bigquery.Table, ...)
- func (bq *BigQuery) GetTable(tableName string) (table *bigquery.Table, err error)
- func (bq *BigQuery) InitializeTable(tableName string, schemaFileName string, t proto.Message, ...) (out *bigquery.Table, err error)
- func (bq *BigQuery) Query(sql string) *bigquery.Query
- func (bq *BigQuery) TableExists(tableName string) (out bool)
- type Config
- type KeyValuePair
- type Logger
- type MessageLoaderWrapper
- type Module
Constants ¶
const ( // LogNameFormat is a constant used as "<module_name>_<log_name>_<environment>" LogNameFormat = "%s_%s_%s" DBNameFormat = "%s_%s" DefaultLogName = "app" DBLogName = "bq" )
Constants here define the naming conventions used by the database, logging, and pubsub topics used by the modules. This notion uses the following convention rules from the configuration file: <module_name>_?_environment this convention allows the common to exist across multiple projects and variant environments to support business and testing needs.
const (
BigQueryDateFormat = "2006-01-02 15:04:05"
)
const (
FlagConfigFile = "configFile"
)
Variables ¶
This section is empty.
Functions ¶
func ConvertMessageToBigQueryType ¶
func ConvertMessageToBigQueryType(t proto.Message) bigquery.ValueSaver
ConvertMessageToBigQueryType converts from a message into a message save type
func QueryableNameFromQualifiedName ¶
QueryableNameFromQualifiedName - removes the project name with : from the qualified name
Types ¶
type BaseModule ¶
type BaseModule struct { // Config - The configuration loaded into the common Config *Config // BigQuery - The limited BigQuery object, hiding the client and close method // to ensure safe operation. BigQuery *BigQuery // contains filtered or unexported fields }
BaseModule is the primary structure used for holding state objects.
func (*BaseModule) Close ¶
func (module *BaseModule) Close()
Close - is used to safely close all related objects and instances.
func (*BaseModule) GetBigQuery ¶
func (module *BaseModule) GetBigQuery() *BigQuery
func (*BaseModule) GetConfig ¶
func (module *BaseModule) GetConfig() *Config
func (*BaseModule) GetDefaultLog ¶
func (module *BaseModule) GetDefaultLog() *log.Logger
func (*BaseModule) GetDefaultLogger ¶
func (module *BaseModule) GetDefaultLogger() *log.Logger
GetDefaultLogger - returns a default logger
func (*BaseModule) GetLogger ¶
func (module *BaseModule) GetLogger() *Logger
type BigQuery ¶
type BigQuery struct {
// contains filtered or unexported fields
}
BigQuery is a state holder for the bigquery.Client, and bigquery.Dataset. This allows for safe concurrent access to the datastore and its tables.
func NewBigQuery ¶
func NewBigQuery( ctx context.Context, projectId string, log *log.Logger, datasetName string) (*BigQuery, error)
NewBigQuery is the default constructor for the BigQuery object
func (*BigQuery) CreateTableFromSchema ¶
func (bq *BigQuery) CreateTableFromSchema( tableName string, schema bigquery.Schema, table *bigquery.Table, labels map[string]string)
CreateTableFromSchema creates a table from a bq Schema
func (*BigQuery) GetTable ¶
GetTable will get a table from BQ if the table exists, otherwise returns an error
func (*BigQuery) InitializeTable ¶
func (bq *BigQuery) InitializeTable( tableName string, schemaFileName string, t proto.Message, additionalTags map[string]string) (out *bigquery.Table, err error)
InitializeTable - reads a table from the provided schema or creates the schema from the struct. Once the schema is created, it is used to create the table if the table does not exist. Once created or read, the table is cached for future use.
func (*BigQuery) TableExists ¶
TableExists determines if the table is already in the dataset
type Config ¶
type Config struct { ProjectId string `json:"project_id"` Name string `json:"name"` Environment string `json:"env"` Enabled bool `json:"enabled"` LogLevel string `json:"log_level"` Labels map[string]string `json:"labels"` }
Config is the primary configuration state holder and TO definition.
func LoadConfig ¶
LoadConfig is used for loading a configuration file from disk.
func LoadConfigFromFlags ¶
type KeyValuePair ¶
KeyValuePair is a simple stucture for holding key value pairs
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the primary wrapper for holding the logging clinet and map of available / registered loggers and the configured severity level.
type MessageLoaderWrapper ¶
type MessageLoaderWrapper struct {
// contains filtered or unexported fields
}
MessageLoaderWrapper - is a wrapper used to reduce total number of dependencies in other common projects.
func ConvertFromBigQueryToMessage ¶
func ConvertFromBigQueryToMessage(t proto.Message) *MessageLoaderWrapper
ConvertFromBigQueryToMessage converts from the BQ schema into a structured protobuf message type.
func (*MessageLoaderWrapper) GetMessage ¶
func (w *MessageLoaderWrapper) GetMessage() proto.Message
GetMessage is a helper method for converting a wrapped message into a protobuf message
type Module ¶
type Module interface { // GetConfig returns a Configuration object GetConfig() *Config // GetBigQuery returns a BigQuery wrapper object GetBigQuery() *BigQuery // GetLogger returns the underlying cloud logger GetLogger() *Logger // GetDefaultLog returns a native log with a default criticality level. GetDefaultLog() *log.Logger // Close safely releases all resources Close() }
Module is the basic building block for retail domain modules. Each common represents a clear-cut subdomain model of retail. Please see the default documentation for more details on available modules.
func LoadBaseModule ¶
LoadBaseModule - Reads a JSON configuration from disk and initializes the common. if any errors occur, a non-nil error will be returned. The intention of LoadModule is to be used in conjunction with the Main method of an implementing service.
func NewBaseModule ¶
NewBaseModule is a programmatic constructor using a Config object.