internal

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

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAPIURL

func BuildAPIURL(subpaths ...string) string

BuildAPIURL returns a fully-qualified URL with the given path elements accounting for reverse proxy configuration.

func CtxWithUserInfo

func CtxWithUserInfo(c *gin.Context, userinfo []byte)

func GetLoggerFromCtx

func GetLoggerFromCtx(ctx context.Context) *zap.SugaredLogger

func GetUserFromCtx

func GetUserFromCtx(ctx context.Context) *generated.User

func GetUserInfoFromCtx

func GetUserInfoFromCtx(c *gin.Context) (*oidc.UserInfo, error)

func NewAppConfig

func NewAppConfig() error

NewAppConfig initializes app config from current environment variables. config can be replaced with subsequent calls.

func NewErrorWithLocf

func NewErrorWithLocf(code ErrorCode, loc []string, format string, a ...any) error

NewErrorWithLocf instantiates a new error with error location.

func NewErrorf

func NewErrorf(code ErrorCode, format string, a ...any) error

NewErrorf instantiates a new error.

func SetLoggerCtx

func SetLoggerCtx(ctx context.Context, l *zap.SugaredLogger) context.Context

func SetUserCtx

func SetUserCtx(ctx context.Context, u *generated.User) context.Context

func WrapErrorWithLocf

func WrapErrorWithLocf(orig error, code ErrorCode, loc []string, format string, a ...interface{}) error

WrapErrorWithLocf accumulates a given path in loc.

func WrapErrorf

func WrapErrorf(orig error, code ErrorCode, format string, a ...any) error

WrapErrorf returns a wrapped error.

Types

type AppConfig

type AppConfig struct {
	Postgres   PostgresConfig
	KV         KeyValueDbConfig
	TwitchOIDC TwitchOidcConfig
	SuperAdmin SuperAdminConfig
	Twitch     TwitchConfig
	Discord    DiscordConfig

	FrontendPort          string  `env:"FRONTEND_PORT"`
	Domain                string  `env:"DOMAIN"`
	APIPort               string  `env:"API_PORT"`
	APIVersion            string  `env:"API_VERSION"`
	ReverseProxyAPIPrefix *string `env:"REVERSE_PROXY_API_PREFIX"`
	ProjectPrefix         string  `env:"PROJECT_PREFIX"`
	AppEnv                AppEnv  `env:"APP_ENV"`
	SigningKey            string  `env:"SIGNING_KEY"`
	BuildVersion          string  `env:"BUILD_VERSION,-"`
	CookieDomain          string  `env:"COOKIE_DOMAIN"`
	LoginCookieKey        string  `env:"LOGIN_COOKIE_KEY"`
}

AppConfig contains app settings.

var (

	// Config returns the app global config initialized from environment variables.
	// [Read] locks not needed if there are no writes involved. Config is only populated at startup so there won't be any more writes.
	Config *AppConfig
)

type AppEnv

type AppEnv string
const (
	AppEnvDev  AppEnv = "dev"
	AppEnvProd AppEnv = "prod"
	AppEnvCI   AppEnv = "ci"
	AppEnvE2E  AppEnv = "e2e"
)

func (*AppEnv) Decode

func (e *AppEnv) Decode(value string) error

Decode decodes an env var value.

type CtxGinKey

type CtxGinKey = struct{}

type Decoder

type Decoder interface {
	Decode(value string) error
}

type DiscordConfig

type DiscordConfig struct {
	ChannelID string `env:"DISCORD_CHANNEL_ID"`
	BotToken  string `env:"DISCORD_BOT_TOKEN"`
}

type Error

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

Error represents an error that could be wrapping another error, It includes a code for determining what triggered the error.

func (*Error) Cause

func (e *Error) Cause() error

Cause returns the root error cause in the chain.

func (*Error) Code

func (e *Error) Code() ErrorCode

Code returns the code representing this error.

func (*Error) Error

func (e *Error) Error() string

Error returns the message, when wrapping errors the wrapped error is returned.

func (*Error) Loc

func (e *Error) Loc() []string

Loc returns the accumulated error location.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error, if any.

type ErrorCode

type ErrorCode string
const (
	ErrorCodeAlreadyExists      ErrorCode = "AlreadyExists"
	ErrorCodeInvalidArgument    ErrorCode = "InvalidArgument"
	ErrorCodeSignedOut          ErrorCode = "SignedOut"
	ErrorCodeInvalidRole        ErrorCode = "InvalidRole"
	ErrorCodeInvalidScope       ErrorCode = "InvalidScope"
	ErrorCodeInvalidUUID        ErrorCode = "InvalidUUID"
	ErrorCodeNotFound           ErrorCode = "NotFound"
	ErrorCodeOIDC               ErrorCode = "OIDC"
	ErrorCodePrivate            ErrorCode = "Private"
	ErrorCodeRequestValidation  ErrorCode = "RequestValidation"
	ErrorCodeResponseValidation ErrorCode = "ResponseValidation"
	ErrorCodeUnauthenticated    ErrorCode = "Unauthenticated"
	ErrorCodeUnauthorized       ErrorCode = "Unauthorized"
	ErrorCodeUnknown            ErrorCode = "Unknown"
)

Notes: - 'Private' marks an error to be hidden in response.

type KeyValueDbConfig

type KeyValueDbConfig struct {
	DB   int    `env:"KEY_VALUE_DB"`
	Host string `env:"KEY_VALUE_HOST"`
}

KeyValueDbConfig contains key-value db settings.

type PostgresConfig

type PostgresConfig struct {
	// Port represents the db port to use in the application, depending on setup (dockerized or not).
	Port     string `env:"DB_PORT"`
	User     string `env:"POSTGRES_USER"`
	Password string `env:"POSTGRES_PASSWORD"`
	Server   string `env:"POSTGRES_SERVER"`
	DB       string `env:"POSTGRES_DB"`
	// Ent with pgx v5 will allow to trace queries.
	TraceEnabled bool `env:"POSTGRES_TRACE,false"`
}

type SuperAdminConfig

type SuperAdminConfig struct {
	// manually set a user to be superadmin.
	// Alternatively we could have a special admin dashboard but we can stick to twitch login for now.
	Email string `env:"SUPERADMIN_EMAIL"`
}

type TwitchConfig

type TwitchConfig struct {
	BroadcasterID     string
	BroadcasterName   string
	AuthInfoCookieKey string
}

type TwitchOidcConfig

type TwitchOidcConfig struct {
	ClientID     string `env:"OIDC_TWITCH_CLIENT_ID"`
	ClientSecret string `env:"OIDC_TWITCH_CLIENT_SECRET"`
	Issuer       string
	// Streamer scopes for code flow API usage with refresh_token.
	BroadcasterScopes string
	// User scopes.
	UserScopes string
	Domain     string
}

Directories

Path Synopsis
ent
privacy/token
Package token provides policy wrappers / getters for queries and mutations during password reset, sign-up
Package token provides policy wrappers / getters for queries and mutations during password reset, sign-up
privacy/utils
Package utils is a helper for working with ent policies
Package utils is a helper for working with ent policies
schema
file: internal/ent/schema/refreshtoken.go
file: internal/ent/schema/refreshtoken.go
*
gql
nolint: tagliatelle
nolint: tagliatelle
utils

Jump to

Keyboard shortcuts

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