config

package
v0.0.0-...-4eb781d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Examples

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 interface{}) error

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

Example
var config struct {
	CacheRedis Redis `json:"cache_redis"`
}

err := FromEnvironment(os.Getenv, &config)
if err != nil {
	panic(err)
}
Output:

Types

type AWS

type AWS struct {
	AccessKeyID     string `json:"access_key_id"`
	AccessKeySecret string `json:"access_key_secret"`

	Region string `json:"region,omitempty"`
}

AWS configures credentials for access to Amazon Web Services. It is intended to be used in composition rather than a key.

func (AWS) Credentials

func (a AWS) Credentials() *credentials.Credentials

Credentials returns a configured set of AWS credentials.

func (AWS) Session

func (a AWS) Session() (*session.Session, error)

Session returns an AWS Session configured with region and credentials.

type Getter

type Getter func(string) string

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

type JWT

type JWT struct {
	Issuer  string `json:"issuer"`
	Public  string `json:"public"`
	Private string `json:"private,omitempty"`
}

JWT configures public (and optionally private) keys and issuer for JSON Web Tokens. It is intended to be used in composition rather than a key.

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() (*mongodb.Database, error)

Connect returns a connected mongo.Database instance.

func (MongoDB) Options

func (m MongoDB) Options() (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() (*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) GracefulTimeout

func (cfg *Server) GracefulTimeout() time.Duration

func (*Server) Listen

func (cfg *Server) Listen() (net.Listener, error)

func (*Server) ListenAndServe

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

ListenAndServe configures a HTTP server and begins listening for clients.

func (*Server) Serve

func (cfg *Server) Serve(ctx context.Context, l net.Listener, srv *http.Server) (err error)

Serve the HTTP requests on the specified listener, and gracefully close when the context is cancelled.

type UnderwriterOpts

type UnderwriterOpts struct {
	IncludeUnreleased bool `json:"include_unreleased"`
}

UnderwriterOpts represents the underwriters info/models options.

Jump to

Keyboard shortcuts

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