Documentation
¶
Overview ¶
config package from micro-strter-kit import myConfig "github.com/xmlking/grpc-starter-kit/internal/config" to `main.go` and all test files. then use Helper Methods `config.GetServiceConfig()` anywhere you need to retrieve `Configuration`
Index ¶
- Variables
- func GetBuildInfo() string
- func GetClientConn(service *Service, ucInterceptors []grpc.UnaryClientInterceptor) (clientConn *grpc.ClientConn, err error)
- func IsProduction() bool
- func IsSecure() bool
- type Configuration
- type DatabaseConfiguration
- type EmailConfiguration
- type Features
- type Features_Metrics
- type Features_Rpclog
- type Features_TLS
- type Features_Tracing
- type Features_Translog
- type Features_Validator
- type Service
- type Services
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 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 )
Functions ¶
func GetBuildInfo ¶
func GetBuildInfo() string
func GetClientConn ¶
func GetClientConn(service *Service, ucInterceptors []grpc.UnaryClientInterceptor) (clientConn *grpc.ClientConn, err error)
func IsProduction ¶
func IsProduction() bool
Types ¶
type Configuration ¶
type Configuration struct { Database *DatabaseConfiguration `yaml:"database,omitempty"` Email *EmailConfiguration `yaml:"email,omitempty"` Features *Features `yaml:"features,omitempty"` Services *Services `yaml:"services,omitempty"` }
func GetConfig ¶
func GetConfig() Configuration
Example ¶
package main import ( "fmt" "github.com/xmlking/grpc-starter-kit/internal/config" ) func main() { fmt.Println(config.GetConfig().Email) // fmt.Println(config.GetConfig().Services.Account.Authority) }
Output: &{yourGmailUsername yourGmailAppPassword smtp.gmail.com 587 from-test@gmail.com}
Example (Check_defaults) ¶
package main import ( "fmt" "github.com/xmlking/grpc-starter-kit/internal/config" ) func main() { fmt.Println(config.GetConfig().Services.Account.Endpoint) fmt.Println(config.GetConfig().Services.Account.Version) fmt.Println(config.GetConfig().Services.Account.Authority) }
Output: dns:///account.test:8080 v0.1.0 aaa.bbb.ccc
type DatabaseConfiguration ¶
type DatabaseConfiguration struct { Dialect string `yaml:",omitempty" valid:"in(mysql|sqlite3|postgres|gremlin)" default:"sqlite3"` Host string `yaml:",omitempty" valid:"host"` Port uint32 `yaml:",omitempty" default:"5432" valid:"port"` Username string `yaml:"username,omitempty" valid:"alphanum,required"` Password string `yaml:"password,omitempty" valid:"alphanum,required"` Database string `yaml:"database,omitempty" valid:"type(string),required"` Charset string `yaml:",omitempty" default:"utf8"` Utc bool `yaml:",omitempty" default:"true"` Logging bool `yaml:",omitempty" default:"false"` Singularize bool `yaml:",omitempty" default:"false"` MaxOpenConns int `yaml:"max_open_conns,omitempty" default:"100"` MaxIdleConns int `yaml:"max_idle_conns,omitempty" default:"10"` ConnMaxLifetime *time.Duration `yaml:"conn_max_lifetime,omitempty" default:"1h"` }
func (*DatabaseConfiguration) URL ¶
func (d *DatabaseConfiguration) URL() (url string, err error)
URL returns a connection string for the database.
type EmailConfiguration ¶
type Features ¶
type Features struct { Metrics *Features_Metrics `yaml:"metrics,omitempty"` Tracing *Features_Tracing `yaml:"tracing,omitempty"` Tls *Features_TLS `yaml:"tls,omitempty"` Validator *Features_Validator `yaml:"validator,omitempty"` Rpclog *Features_Rpclog `yaml:"rpclog,omitempty"` Translog *Features_Translog `yaml:"translog,omitempty"` }
type Features_Metrics ¶
type Features_Rpclog ¶
type Features_Rpclog struct {
Enabled bool `yaml:",omitempty" default:"false"`
}
type Features_TLS ¶
type Features_TLS struct { Enabled bool `yaml:",omitempty" default:"false"` CertFile string `yaml:"cert_file" valid:"type(string),required"` KeyFile string `yaml:"key_file" valid:"type(string),required"` CaFile string `yaml:"ca_file" valid:"type(string),required"` Password string `yaml:"password,omitempty"` ServerName string `yaml:"server_name,omitempty" default:"'*'"` }
type Features_Tracing ¶
type Features_Translog ¶
type Features_Validator ¶
type Features_Validator struct {
Enabled bool `yaml:",omitempty" default:"false"`
}
type Service ¶
type Service struct { Endpoint string `yaml:"endpoint" required:"true"` Version string `yaml:",omitempty" default:"v0.1.0"` Metadata map[string]string `yaml:",omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` ServiceConfig string `yaml:"service_config,omitempty"` Authority string `yaml:",omitempty"` }
Click to show internal directories.
Click to hide internal directories.