config

package
v0.0.0-...-c4ca307 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT, MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const ConfigEnvironmentVariable = "CONFIG"

ConfigEnvironmentVariable is the expected environment variable storing JSON configuration data.

View Source
const DefaultGraceful = 5

DefaultGraceful is the graceful shutdown timeout applied when no configuration value is given.

Variables

This section is empty.

Functions

func ContextWithCancelOnSignal

func ContextWithCancelOnSignal(ctx context.Context) context.Context

func EnvironmentName

func EnvironmentName(get Getter) string

EnvironmentName returns the name of the current execution environment from CONFIG. If no environment is detected, "local" is returned.

func FromEnvironment

func FromEnvironment(get Getter, dst any) error

FromEnvironment unmarshals JSON configuration from the CONFIG environment variable into dst.

Types

type Getter

type Getter func(string) string

Getter takes an environment variable name, and returns its value or "" if not set.

type MongoDB

type MongoDB struct {
	URI             string         `json:"uri"`
	ConnectTimeout  time.Duration  `json:"connect_timeout"`
	MaxConnIdleTime *time.Duration `json:"max_conn_idle_time"`
	MaxConnecting   *uint64        `json:"max_connecting"`
	MaxPoolSize     *uint64        `json:"max_pool_size"`
	MinPoolSize     *uint64        `json:"min_pool_size"`
}

MongoDB configures a connection to a Mongo database.

func (MongoDB) Connect

func (m MongoDB) Connect(ctx context.Context) (*mongodb.Database, error)

Connect returns a connected mongo.Database instance.

func (MongoDB) Options

func (m MongoDB) Options(ctx context.Context) (opts *options.ClientOptions, dbName string, err error)

Options returns the MongoDB client options and database name.

type Redis

type Redis struct {
	URI          string        `json:"uri"`
	DialTimeout  time.Duration `json:"dial_timeout"`
	ReadTimeout  time.Duration `json:"read_timeout"`
	WriteTimeout time.Duration `json:"write_timeout"`
}

Redis configures a connection to a Redis database.

func (Redis) Connect

func (r Redis) Connect(ctx context.Context) (*redis.Client, error)

Connect returns a connected redis.Client instance.

func (Redis) Options

func (r Redis) Options() (*redis.Options, error)

Options returns a configured redis.Options structure.

type Server

type Server struct {
	Addr string `json:"addr"`

	// Graceful enables graceful shutdown and is the time in seconds to wait
	// for all outstanding requests to terminate before forceably killing the
	// server. When no value is given, DefaultGraceful is used. Graceful
	// shutdown is disabled when less than zero.
	Graceful int `json:"graceful"`
}

Server configures the binding and security of an HTTP server.

func (*Server) ListenAndServe

func (cfg *Server) ListenAndServe(srv *http.Server) error

ListenAndServe configures a HTTP server and begins listening for clients.

Jump to

Keyboard shortcuts

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