config

package
v0.0.0-...-97fb934 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 35 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultConfigPath = "config.yml"

	SQLDialectMysql    = "mysql"
	SQLDialectPostgres = "postgres"
	SQLDialectSqlite   = "sqlite3"
	SQLDialectMssql    = "mssql"

	KeyLatestTotalTime              = "latest_total_time"
	KeyLatestTotalUsers             = "latest_total_users"
	KeyLastImport                   = "last_import"            // import attempt
	KeyLastImportSuccess            = "last_successful_import" // last actual successful import
	KeySubscriptionNotificationSent = "sub_reminder"
	KeyNewsbox                      = "newsbox"
	KeyInviteCode                   = "invite"
	KeySharedData                   = "shared_data"

	CookieKeySession               = "wakapi_session"
	CookieKeyAuth                  = "wakapi_auth"
	SessionValueOidcState          = "oidc_state"
	SessionValueOidcIdTokenPayload = "oidc_id_token"

	SimpleDateFormat     = "2006-01-02"
	SimpleDateTimeFormat = "2006-01-02 15:04:05"

	ErrUnauthorized        = "401 unauthorized"
	ErrBadRequest          = "400 bad request"
	ErrNotFound            = "404 not found"
	ErrInternalServerError = "500 internal server error"
)
View Source
const (
	WakatimeApiUrl               = "https://api.wakatime.com/api/v1"
	WakatimeApiUserUrl           = "/users/current"
	WakatimeApiAllTimeUrl        = "/users/current/all_time_since_today"
	WakatimeApiHeartbeatsUrl     = "/users/current/heartbeats"
	WakatimeApiHeartbeatsBulkUrl = "/users/current/heartbeats.bulk"
	WakatimeApiUserAgentsUrl     = "/users/current/user_agents"
	WakatimeApiMachineNamesUrl   = "/users/current/machine_names"
	WakatimeApiDataDumpUrl       = "/users/current/data_dumps"
)
View Source
const (
	TopicUser                    = "user.*"
	TopicHeartbeat               = "heartbeat.*"
	TopicProjectLabel            = "project_label.*"
	EventUserUpdate              = "user.update"
	EventUserDelete              = "user.delete"
	EventHeartbeatCreate         = "heartbeat.create"
	EventProjectLabelCreate      = "project_label.create"
	EventProjectLabelDelete      = "project_label.delete"
	EventWakatimeFailure         = "wakatime.failure"
	EventLanguageMappingsChanged = "language_mappings.changed"
	EventApiKeyCreate            = "api_key.create"
	EventApiKeyDelete            = "api_key.delete"
	FieldPayload                 = "payload"
	FieldUser                    = "user"
	FieldUserId                  = "user.id"
)
View Source
const (
	QueueDefault      = "wakapi.default"
	QueueProcessing   = "wakapi.processing"
	QueueProcessing2  = "wakapi.processing_2"
	QueueReports      = "wakapi.reports"
	QueueMails        = "wakapi.mail"
	QueueImports      = "wakapi.imports"
	QueueHousekeeping = "wakapi.housekeeping"
)
View Source
const (
	MiddlewareKeyPrincipal   = SharedDataKey("principal")
	MiddlewareKeyPrincipalId = SharedDataKey("principal_identity")
)
View Source
const (
	IndexTemplate         = "index.tpl.html"
	LoginTemplate         = "login.tpl.html"
	ImprintTemplate       = "imprint.tpl.html"
	SetupTemplate         = "setup.tpl.html"
	SignupTemplate        = "signup.tpl.html"
	SetPasswordTemplate   = "set-password.tpl.html"
	ResetPasswordTemplate = "reset-password.tpl.html"
	SettingsTemplate      = "settings.tpl.html"
	SummaryTemplate       = "summary.tpl.html"
	LeaderboardTemplate   = "leaderboard.tpl.html"
	ProjectsTemplate      = "projects.tpl.html"
)
View Source
const (
	MailProviderSmtp = "smtp"
)

Variables

This section is empty.

Functions

func BeginningOfWakatime

func BeginningOfWakatime() time.Time

func ChooseFS

func ChooseFS(localDir string, embeddedFS fs.FS) fs.FS

ChooseFS returns a local (DirFS) file system when on 'dev' environment and the given go-embed file system otherwise

func CloseQueues

func CloseQueues()

func EventBus

func EventBus() *hub.Hub

func GetDefaultQueue

func GetDefaultQueue() *artifex.Dispatcher

func GetQueue

func GetQueue(name string) *artifex.Dispatcher

func GetSessionStore

func GetSessionStore() *sessions.CookieStore

func InitLogger

func InitLogger(isDev bool)

func InitQueue

func InitQueue(name string, workers int) error

func IsDev

func IsDev(env string) bool

func NewSessionStore

func NewSessionStore() *sessions.CookieStore

func RegisterOidcProvider

func RegisterOidcProvider(providerCfg *oidcProviderConfig)

func Set

func Set(config *Config)

func StartJobs

func StartJobs()

Types

type ApplicationEvent

type ApplicationEvent struct {
	Type    string
	Payload interface{}
}

type Config

type Config struct {
	Env            string `default:"dev" env:"ENVIRONMENT"`
	Version        string `yaml:"-"`
	QuickStart     bool   `yaml:"quick_start" env:"WAKAPI_QUICK_START"`
	SkipMigrations bool   `yaml:"skip_migrations" env:"WAKAPI_SKIP_MIGRATIONS"`
	InstanceId     string `yaml:"-"` // only temporary, changes between runs
	EnablePprof    bool   `yaml:"enable_pprof" env:"WAKAPI_ENABLE_PPROF"`
	App            appConfig
	Security       securityConfig
	Db             dbConfig
	Server         serverConfig
	Subscriptions  subscriptionsConfig
	Sentry         sentryConfig
	Mail           mailConfig
}

func Empty

func Empty() *Config

func Get

func Get() *Config

func Load

func Load(configFlag string, version string) *Config

func WithOidcProvider

func WithOidcProvider(c *Config, name, clientId, clientSecret, Endpoint string) *Config

func (*Config) AppStartTimestamp

func (c *Config) AppStartTimestamp() string

func (*Config) CreateCookie

func (c *Config) CreateCookie(name, value string) *http.Cookie

func (*Config) GetClearCookie

func (c *Config) GetClearCookie(name string) *http.Cookie

func (*Config) IsDev

func (c *Config) IsDev() bool

func (*Config) UseTLS

func (c *Config) UseTLS() bool

type IdTokenPayload

type IdTokenPayload struct {
	Issuer            string `json:"iss"`
	Subject           string `json:"sub"`
	Expiry            int64  `json:"exp"`
	Name              string `json:"name"`
	Nickname          string `json:"nickname"`
	PreferredUsername string `json:"preferred_username"`
	Email             string `json:"email"`
	EmailVerified     bool   `json:"email_verified"`
	ProviderName      string `json:"provider_name"` // custom field, not part of actual id token response
}

func (*IdTokenPayload) Exp

func (token *IdTokenPayload) Exp() time.Time

func (*IdTokenPayload) IsValid

func (token *IdTokenPayload) IsValid() bool

func (*IdTokenPayload) Username

func (token *IdTokenPayload) Username() string

type JobQueueMetrics

type JobQueueMetrics struct {
	Queue        string
	EnqueuedJobs int
	FinishedJobs int
}

func GetQueueMetrics

func GetQueueMetrics() []*JobQueueMetrics

type OidcProvider

type OidcProvider struct {
	Name        string
	DisplayName string
	OAuth2      *oauth2.Config
	Verifier    *oidc.IDTokenVerifier
}

func GetOidcProvider

func GetOidcProvider(name string) (*OidcProvider, error)

func MustGetOidcProvider

func MustGetOidcProvider(name string) *OidcProvider

type SMTPMailConfig

type SMTPMailConfig struct {
	Host       string `env:"WAKAPI_MAIL_SMTP_HOST"`
	Port       uint   `env:"WAKAPI_MAIL_SMTP_PORT"`
	Username   string `env:"WAKAPI_MAIL_SMTP_USER"`
	Password   string `env:"WAKAPI_MAIL_SMTP_PASS"`
	TLS        bool   `env:"WAKAPI_MAIL_SMTP_TLS"`
	SkipVerify bool   `env:"WAKAPI_MAIL_SMTP_SKIP_VERIFY"`
}

func (*SMTPMailConfig) ConnStr

func (c *SMTPMailConfig) ConnStr() string

type SentryLogger

type SentryLogger struct {
	*slog.Logger
}

SentryLogger wraps slog.Logger and provides a Fatal method

func Log

func Log() *SentryLogger

func New

func New() *SentryLogger

func (*SentryLogger) Fatal

func (l *SentryLogger) Fatal(msg string, args ...any)

func (*SentryLogger) Request

func (l *SentryLogger) Request(r *http.Request) *SentryLogger

type SharedData

type SharedData struct {
	*lib.ConcurrentMap[SharedDataKey, interface{}]
}

func NewSharedData

func NewSharedData() *SharedData

type SharedDataKey

type SharedDataKey string

type WakapiDBOpts

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

func GetWakapiDBOpts

func GetWakapiDBOpts(dbConfig *dbConfig) *WakapiDBOpts

func (WakapiDBOpts) AfterInitialize

func (opts WakapiDBOpts) AfterInitialize(db *gorm.DB) error

func (WakapiDBOpts) Apply

func (opts WakapiDBOpts) Apply(config *gorm.Config) error

Jump to

Keyboard shortcuts

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