settings

package
v0.0.0-...-834fbee Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeviceID

func DeviceID(ctx context.Context) (string, error)

DeviceID returns device ID from context gRPC MetaData.

func ForwardedFor

func ForwardedFor(ctx context.Context) (string, []string, error)

ForwardedFor returns real IP and proxy IPs from context gRPC MetaData.

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

GetLogger returns logger from the context.

func RequestID

func RequestID(ctx context.Context) (string, error)

RequestID returns request ID from context gRPC MetaData.

func SessionID

func SessionID(ctx context.Context) (string, error)

SessionID returns session ID from context gRPC MetaData.

func Set

func Set(ctx context.Context, s *Settings) context.Context

Set returns a new context with set (or re-set) settings.

func SetLogger

func SetLogger(ctx context.Context, l *zap.Logger) context.Context

SetLogger returns a new context with set (or re-set) logger.

func SetRequestMetaData

func SetRequestMetaData(ctx context.Context, s *RequestMetaData) context.Context

SetRequestMetaData returns a new context with set RequestMetaData.

func UserAgent

func UserAgent(ctx context.Context) (string, error)

UserAgent returns user agent from context gRPC MetaData.

Types

type ApiConfig

type ApiConfig struct {
	GRPCListenAddress    string `json:"grpc_listen_address"`
	GRPCWebListenAddress string `json:"grpc_web_listen_address"`
	RESTListenAddress    string `json:"rest_listen_address"`
}

type DebugConfig

type DebugConfig struct {
	DebugEmailPattern       string `json:"debug_email_pattern"`
	EnableReflection        bool   `json:"enable_reflection"`
	EnableDevelopmentLogger bool   `json:"enable_development_logger"`
	EnableDebugLevelLogger  bool   `json:"enable_debug_level_logger"`
}

type PostgresConfig

type PostgresConfig struct {
	URL             string        `json:"url"`
	ConnMaxLifetime time.Duration `json:"conn_max_lifetime"`
	MaxOpenConns    int           `json:"max_open_conns"`
	MaxIdleConns    int           `json:"max_idle_conns"`
}

type PrometheusConfig

type PrometheusConfig struct {
	MetricsListenAddress string `json:"metrics_listen_address"`
	RegSerivceName       string `json:"reg_service_name"`
}

type Reloader

type Reloader struct {
	// contains filtered or unexported fields
}

Reloader provides current application configuration for other packages.

It reloads settings from Consul.

func ConnectAndRunReloader

func ConnectAndRunReloader(ctx context.Context, consulAddrs, consulKey string) (*Reloader, *consul.Client)

func NewReloader

func NewReloader(consulClient *consul.Client, consulKey string) *Reloader

func (*Reloader) PutSettings

func (r *Reloader) PutSettings(s *Settings) error

PutSettings stores given settings in Consul.

func (*Reloader) Run

func (r *Reloader) Run(ctx context.Context)

func (*Reloader) Settings

func (r *Reloader) Settings() *Settings

Settings returns current settings.

If no settings are available yet, this method blocks.

Caller should not modify returned settings in any way.

type RequestMetaData

type RequestMetaData struct {
	SessionID string
	RequestID string
	DeviceID  string
	RealIP    string
	ProxyIPs  []string
	UserAgent string
}

func GetRequestMetaData

func GetRequestMetaData(ctx context.Context) *RequestMetaData

GetRequestMetaData returns RequestMetaData from the context.

func ParseRequestMetaData

func ParseRequestMetaData(ctx context.Context) (md *RequestMetaData, err error)

ParseRequestMetaData returns request meta data from context MetaData gRPC.

type SentryConfig

type SentryConfig struct {
	DSN string `json:"dsn"`
}

type Settings

type Settings struct {
	Postgres PostgresConfig `json:"postgres"`

	API ApiConfig `json:"api"`

	Debug      DebugConfig      `json:"debug"`
	Sentry     SentryConfig     `json:"sentry"`
	Prometheus PrometheusConfig `json:"prometheus_config"`
}

func Get

func Get(ctx context.Context) *Settings

Get returns settings from the context.

Jump to

Keyboard shortcuts

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