Documentation ¶
Overview ¶
Package def provides default values for both commands and tests.
Index ¶
- Constants
- Variables
- func Init() error
- func MergeCancel(parent context.Context, extra Cancellation) (ctx context.Context, cancel context.CancelFunc)
- func NewContext(service string) context.Context
- func NewGoose(service string) *goose.Instance
- func NewMySQLConfig(cfg MySQLConfig) *mysql.Config
- func Version() string
- type Cancellation
- type Metrics
- type MySQLConfig
- type PostgresConfig
Constants ¶
const ( LogServer = "server" // "OpenAPI", "gRPC", "Prometheus metrics", etc. LogRemoteIP = "remoteIP" // IP address. LogAddr = "addr" // host:port. LogHost = "host" // DNS hostname or IPv4/IPv6 address. LogPort = "port" // TCP/UDP port number. LogFunc = "func" // RPC/event handler method name, REST resource path. LogUserName = "userName" LogGRPCCode = "grpcCode" )
Log field names.
const ( PostgresDefaultStatementTimeout = 3 * time.Second PostgresDefaultLockTimeout = 3 * time.Second PostgresDefaultIdleInTransactionSessionTimeout = 10 * time.Second )
Default timeouts for PostgreSQL.
Variables ¶
var ( ProgName = strings.TrimSuffix(path.Base(os.Args[0]), ".test") Hostname, _ = os.Hostname() TestSecond = time.Duration(float64(time.Second) * testTimeFactor) TestTimeout = 7 * TestSecond )
Constants.
Functions ¶
func Init ¶
func Init() error
Init must be called once before using this package. It provides common initialization for both commands and tests.
func MergeCancel ¶ added in v0.3.0
func MergeCancel(parent context.Context, extra Cancellation) (ctx context.Context, cancel context.CancelFunc)
MergeCancel implements proposal https://github.com/golang/go/issues/36503.
func NewContext ¶
NewContext returns context.Background() which contains logger configured for given service.
func NewGoose ¶
func NewGoose(service string) *goose.Instance
NewGoose creates a goose instance with configured logger.
func NewMySQLConfig ¶
func NewMySQLConfig(cfg MySQLConfig) *mysql.Config
NewMySQLConfig creates a new default config for MySQL.
Types ¶
type Cancellation ¶ added in v0.3.0
type Cancellation interface { Deadline() (deadline time.Time, ok bool) Done() <-chan struct{} Err() error }
A Cancellation is an interface capturing only the deadline and cancellation functionality of a context.
type Metrics ¶
type Metrics struct { PanicsTotal prometheus.Counter MisconfigurationTotal prometheus.Counter }
Metrics shared by all packages.
func NewMetrics ¶
func NewMetrics(reg *prometheus.Registry) Metrics
NewMetrics registers and returns metrics shared by all packages.
type MySQLConfig ¶
MySQLConfig contains MySQL connection and authentication details.
type PostgresConfig ¶ added in v0.4.0
PostgresConfig described connection parameters for github.com/lib/pq.
func NewPostgresConfig ¶ added in v0.4.0
func NewPostgresConfig(cfg pqx.Config) *PostgresConfig
NewPostgresConfig creates a new default config for PostgreSQL.
func (*PostgresConfig) Clone ¶ added in v0.4.0
func (c *PostgresConfig) Clone() *PostgresConfig
Clone returns a deep copy.
func (*PostgresConfig) UpdateConnectTimeout ¶ added in v0.4.0
func (c *PostgresConfig) UpdateConnectTimeout(ctx context.Context) error
UpdateConnectTimeout updates c accordingly to ctx.Deadline if c.ConnectTimeout isn't set or larger than ctx.Deadline.