config

package
v0.0.0-...-38bf20c Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DatabaseMigrationTable = "migrations"

The DatabaseMigrationTable name is baked into the binary This setting should always be in sync with dbconfig.yml, sqlboiler.toml and the live database (e.g. to be able to test producation dumps locally)

Variables

View Source
var (
	ModuleName = "build.local/misses/ldflags"               // e.g. "github.com/elganador7/testherobackend/"
	Commit     = "< 40 chars git commit hash via ldflags >" // e.g. "59cb7684dd0b0f38d68cd7db657cb614feba8f7e"
	BuildDate  = "1970-01-01T00:00:00+00:00"                // e.g. "1970-01-01T00:00:00+00:00"
)

The following vars are automatically injected via -ldflags. See Makefile target "make go-build" and make var $(LDFLAGS). No need to change them here. https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications

View Source
var DatabaseMigrationFolder = filepath.Join(util.GetProjectRootDir(), "/migrations")

The DatabaseMigrationFolder (folder with all *.sql migrations). This settings should always be in sync with dbconfig.yaml and Dockerfile (the final app stage). It's expected that the migrations folder lives at the root of this project or right next to the app binary.

Functions

func DotEnvLoad

func DotEnvLoad(absolutePathToEnvFile string, setEnvFn envSetter) error

DotEnvLoad forcefully overrides ENV variables through the supplied .env file.

This mechanism should only be used **locally** to easily inject (gitignored) secrets into your ENV.

When running normally (not within tests): DotEnvLoad("/path/to/my.env.local", os.SetEnv)

For tests (and ENV var autoreset) use t.Setenv: DotEnvLoad("/path/to/my.env.test.local", func(k string, v string) error { t.Setenv(k, v); return nil })

func DotEnvTryLoad

func DotEnvTryLoad(absolutePathToEnvFile string, setEnvFn envSetter)

DotEnvTryLoad forcefully overrides ENV variables through **a maybe available** .env file.

This function will always remain silent if a .env file does not exist! If we successfully apply an ENV file, we will log a warning. If there are any other errors, we will panic!

This mechanism should only be used **locally** to easily inject (gitignored) secrets into your ENV. Non-existing .env files are actually the **best case**.

When running normally (not within tests): DotEnvTryLoad("/path/tp/my.env.local", os.SetEnv)

For tests (and autoreset) use t.Setenv: DotEnvTryLoad("/path/to/my.env.test.local", func(k string, v string) error { t.Setenv(k, v); return nil })

func GetFormattedBuildArgs

func GetFormattedBuildArgs() string

GetFormattedBuildArgs returns string representation of buildsargs set via ldflags "<ModuleName> @ <Commit> (<BuildDate>)"

Types

type AuthServer

type AuthServer struct {
	AccessTokenValidity                time.Duration
	PasswordResetTokenValidity         time.Duration
	PasswordResetTokenDebounceDuration time.Duration
	PasswordResetTokenReuseDuration    time.Duration
	DefaultUserScopes                  []string
	LastAuthenticatedAtThreshold       time.Duration
}

type Database

type Database struct {
	Host             string
	Port             int
	Username         string
	Password         string `json:"-"` // sensitive
	Database         string
	AdditionalParams map[string]string `json:",omitempty"` // Optional additional connection parameters mapped into the connection string
	MaxOpenConns     int
	MaxIdleConns     int
	ConnMaxLifetime  time.Duration
}

func (Database) ConnectionString

func (c Database) ConnectionString() string

ConnectionString generates a connection string to be passed to sql.Open or equivalents, assuming Postgres syntax

type EchoServer

type EchoServer struct {
	Debug                          bool
	ListenAddress                  string
	HideInternalServerErrorDetails bool
	BaseURL                        string
	EnableCORSMiddleware           bool
	EnableLoggerMiddleware         bool
	EnableRecoverMiddleware        bool
	EnableRequestIDMiddleware      bool
	EnableTrailingSlashMiddleware  bool
	EnableSecureMiddleware         bool
	EnableCacheControlMiddleware   bool
	SecureMiddleware               EchoServerSecureMiddleware
}

type EchoServerSecureMiddleware

type EchoServerSecureMiddleware struct {
	XSSProtection         string
	ContentTypeNosniff    string
	XFrameOptions         string
	HSTSMaxAge            int
	HSTSExcludeSubdomains bool
	ContentSecurityPolicy string
	CSPReportOnly         bool
	HSTSPreloadEnabled    bool
	ReferrerPolicy        string
}

EchoServerSecureMiddleware represents a subset of echo's secure middleware config relevant to the app server. https://github.com/labstack/echo/blob/master/middleware/secure.go

type FrontendServer

type FrontendServer struct {
	BaseURL               string
	PasswordResetEndpoint string
}

type I18n

type I18n struct {
	DefaultLanguage language.Tag
	BundleDirAbs    string
}

type LoggerServer

type LoggerServer struct {
	Level              zerolog.Level
	RequestLevel       zerolog.Level
	LogRequestBody     bool
	LogRequestHeader   bool
	LogRequestQuery    bool
	LogResponseBody    bool
	LogResponseHeader  bool
	LogCaller          bool
	PrettyPrintConsole bool
}

type Mailer

type Mailer struct {
	DefaultSender               string
	Send                        bool
	WebTemplatesEmailBaseDirAbs string
	Transporter                 string
}

type MailerTransporter

type MailerTransporter string
var (
	MailerTransporterMock MailerTransporter = "mock"
	MailerTransporterSMTP MailerTransporter = "SMTP"
)

func (MailerTransporter) String

func (m MailerTransporter) String() string

type ManagementServer

type ManagementServer struct {
	Secret                  string `json:"-"` // sensitive
	ReadinessTimeout        time.Duration
	LivenessTimeout         time.Duration
	ProbeWriteablePathsAbs  []string
	ProbeWriteableTouchfile string
}

type PathsServer

type PathsServer struct {
	APIBaseDirAbs string
	MntBaseDirAbs string
}

type PprofServer

type PprofServer struct {
	Enable                      bool
	EnableManagementKeyAuth     bool
	RuntimeBlockProfileRate     int
	RuntimeMutexProfileFraction int
}

type PushService

type PushService struct {
	UseFCMProvider  bool
	UseMockProvider bool
}

type Server

type Server struct {
	Database   Database
	Echo       EchoServer
	Pprof      PprofServer
	Paths      PathsServer
	Auth       AuthServer
	Management ManagementServer
	Mailer     Mailer
	SMTP       transport.SMTPMailTransportConfig
	Frontend   FrontendServer
	Logger     LoggerServer
	Push       PushService
	FCMConfig  provider.FCMConfig
	I18n       I18n
}

func DefaultServiceConfigFromEnv

func DefaultServiceConfigFromEnv() Server

DefaultServiceConfigFromEnv returns the server config as parsed from environment variables and their respective defaults defined below. We don't expect that ENV_VARs change while we are running our application or our tests (and it would be a bad thing to do anyways with parallel testing). Do NOT use os.Setenv / os.Unsetenv in tests utilizing DefaultServiceConfigFromEnv()!

Jump to

Keyboard shortcuts

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