Version: v0.0.0-...-3852566 Latest Latest

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

Go to latest
Published: May 20, 2020 License: MIT Imports: 11 Imported by: 0



config package from micro-strter-kit import myConfig "" to `main.go` and all test files. add myConfig.InitConfig(configDir, configFile), config.Scan(&cfg) in service.Init()



View Source
const (
	// DefaultConfigDir if no ConfigDir supplied
	DefaultConfigDir = "/config"
	// DefaultConfigFile if no ConfigFile supplied
	DefaultConfigFile = "config.yaml"


View Source
var (
	// IsProduction will have CurrentMode of the application
	IsProduction bool

	// Version is populated by govvv in compile-time.
	Version = "untouched"
	// BuildDate is populated by govvv.
	BuildDate string
	// GitCommit is populated by govvv.
	GitCommit string
	// GitBranch is populated by govvv.
	GitBranch string
	// GitState is populated by govvv.
	GitState string
	// GitSummary is populated by govvv.
	GitSummary string


func GetBuildInfo

func GetBuildInfo() string

GetBuildInfo get build info

func InitConfig

func InitConfig(configDir, configFile string)

InitConfig loads the configuration from file then from environment variables and then from cli flags

func LoadExtraConfig

func LoadExtraConfig(configDir, configFile string)

LoadExtraConfig loads the extra configuration from file

func PrintBuildInfo

func PrintBuildInfo()

PrintBuildInfo print build info


type DatabaseConfiguration

type DatabaseConfiguration struct {
	Dialect         DatabaseDialect `json:"dialect" default:"postgres"`
	Host            string          `json:"host"`
	Port            int             `json:"port"`
	Username        string          `json:"username"`
	Password        string          `json:"password"`
	Database        string          `json:"database"`
	Charset         string          `json:"charset" default:"utf8"`
	UTC             bool            `default:"true"`
	Logging         bool            `default:"false"`
	Singularize     bool            `default:"false"`
	MaxOpenConns    int             `json:"maxOpenConns" default:"1"`
	MaxIdleConns    int             `json:"maxIdleConns" default:"1"`
	ConnMaxLifetime time.Duration   `json:"connMaxLifetime" default:"1hr"`

	Params map[string]interface{}

DatabaseConfiguration holds db config

func (*DatabaseConfiguration) URL

func (d *DatabaseConfiguration) URL() (url string, err error)

URL returns a connection string for the database.

type DatabaseDialect

type DatabaseDialect string

DatabaseDialect represents a database dialect constant.

const (
	// PostgreSQLDialect is the dialect name for PostgreSQL.
	PostgreSQLDialect DatabaseDialect = "postgres"
	// MySQLDialect is the dialect name for MySQL.
	MySQLDialect DatabaseDialect = "mysql"
	// SQLiteDialect is the dialect name for SQLite.
	SQLiteDialect DatabaseDialect = "sqlite3"

type EmailConfiguration

type EmailConfiguration struct {
	Username    string
	Password    string
	EmailServer string
	Port        int
	From        string

EmailConfiguration holds email config

type Environment

type Environment string

Environment represents an application environment.

const (
	// Development environment
	Development Environment = "development"
	// Test environment
	Test Environment = "test"
	// Production environment
	Production Environment = "production"

type Feature

type Feature struct {
	Enabled bool `default:"false"`

type LogConfiguration

type LogConfiguration struct {
	Level   string `json:"level"`
	Runtime string `json:"runtime"` // dev, prod, gcp, azure, aws

LogConfiguration holds log config

type Service

type Service struct {
	Endpoint string `json:"endpoint"`
	Version  string `json:"version" default:"v0.1.0"`

type ServiceConfiguration

type ServiceConfiguration struct {
	ServiceName string      `json:"name"`
	Version     string      `json:"version"`
	Environment Environment `json:"environment"`
	Log         LogConfiguration
	Database    DatabaseConfiguration
	Email       EmailConfiguration
	Services    map[string]Service
	Features    map[string]Feature

TODO: use proto to define config.yaml schema ServiceConfiguration is the top level configuration struct which is loaded from the defined source(s)

Jump to

Keyboard shortcuts

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