add templating engine
This commit is contained in:
@@ -21,53 +21,6 @@ import (
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
)
|
||||
|
||||
// TODO: review consts
|
||||
const (
|
||||
// Handlers keys
|
||||
InvalidRequest = "invalid_request"
|
||||
MalformedJSON = "malformed_json"
|
||||
TokenBlacklisted = "token_blacklisted"
|
||||
TokenInvalid = "token_invalid"
|
||||
ValidationFailed = "validation_failed"
|
||||
UntilBeforeTo = "until_before_to"
|
||||
InternalError = "internal_error"
|
||||
NotFound = "not_found"
|
||||
Created = "created"
|
||||
Updated = "updated"
|
||||
Deleted = "deleted"
|
||||
Enabled = "enabled"
|
||||
Disabled = "disabled"
|
||||
Retrieved = "retrieved"
|
||||
ErrorCreating = "error_creating"
|
||||
ErrorUpdating = "error_updating"
|
||||
ErrorEnabling = "error_enabling"
|
||||
ErrorDisabling = "error_disabling"
|
||||
ErrorGetting = "error_getting"
|
||||
ErrorGettingAll = "error_getting_all"
|
||||
ErrorMailing = "error_mailing"
|
||||
InvalidEntityID = "invalid_entity_id"
|
||||
NotImplemented = "not_implemented"
|
||||
NotPassValidation = "not_pass_validation"
|
||||
NotEnoughBalance = "not_enough_balance"
|
||||
InvalidIdentifier = "invalid_identifier"
|
||||
|
||||
// User keys (DB)
|
||||
UserUsernameKey = "username_key"
|
||||
UserEmailKey = "email_key"
|
||||
UsernameAlreadyExists = "username_already_exists"
|
||||
UserSessionKey = "user_session_key"
|
||||
EmailAlreadyExists = "email_already_exists"
|
||||
PhoneNumberKey = "phone_number_key"
|
||||
PhoneAlreadyExists = "phone_already_exists"
|
||||
NoRowsAffected = "no rows in result set"
|
||||
|
||||
// Auth
|
||||
TokenPayload = "token_payload"
|
||||
LoggedIn = "logged_in"
|
||||
IncorrectPassword = "incorrect_password"
|
||||
ErrorGeneratingToken = "error_generating_token"
|
||||
)
|
||||
|
||||
var (
|
||||
logFile *os.File
|
||||
logLevel string
|
||||
@@ -90,10 +43,10 @@ type DatabaseConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
// default ""
|
||||
// default "no-name-defined"
|
||||
Name string
|
||||
|
||||
// default ""
|
||||
// default "v0.0.0"
|
||||
Version string
|
||||
|
||||
// default "development"
|
||||
@@ -111,21 +64,21 @@ type Config struct {
|
||||
// default map[string]DatabaseConfig{}
|
||||
Databases map[string]DatabaseConfig
|
||||
|
||||
// default false
|
||||
CreateTemplates bool
|
||||
|
||||
// default false
|
||||
CreateSession bool
|
||||
|
||||
// default false
|
||||
CreateMailer bool
|
||||
|
||||
// default false
|
||||
CreateTemplates bool
|
||||
}
|
||||
|
||||
type App struct {
|
||||
config Config
|
||||
Session *scs.SessionManager
|
||||
Mailer Mailer
|
||||
//Templates *Templates
|
||||
config Config
|
||||
Templates *Render
|
||||
Session *scs.SessionManager
|
||||
Mailer Mailer
|
||||
}
|
||||
|
||||
type Paseto struct {
|
||||
@@ -248,12 +201,20 @@ func New(config ...Config) *App {
|
||||
"paseto_public_key", cfg.Paseto.PublicKey.ExportHex(),
|
||||
"paseto_duration", cfg.Paseto.Duration.String(),
|
||||
"databases", cfg.Databases,
|
||||
"create_templates", cfg.CreateTemplates,
|
||||
"create_session", cfg.CreateSession,
|
||||
"create_mailer", cfg.CreateMailer,
|
||||
)
|
||||
|
||||
if cfg.EnvMode != EnvironmentProduction {
|
||||
slog.Info("paseto_assymetric_key", "key", cfg.Paseto.AsymmetricKey.ExportHex())
|
||||
}
|
||||
|
||||
if cfg.CreateTemplates {
|
||||
slog.Debug("creating templates")
|
||||
app.Templates = NewHTMLRender()
|
||||
}
|
||||
|
||||
if cfg.CreateSession {
|
||||
slog.Debug("creating session")
|
||||
app.Session = scs.New()
|
||||
@@ -283,14 +244,14 @@ func (a *App) LogLevel() slog.Level {
|
||||
return a.config.LogLevel
|
||||
}
|
||||
|
||||
func (a *App) Paseto() *Paseto {
|
||||
return a.config.Paseto
|
||||
}
|
||||
|
||||
func (a *App) Timezone() string {
|
||||
return a.config.Timezone
|
||||
}
|
||||
|
||||
func (a *App) Paseto() *Paseto {
|
||||
return a.config.Paseto
|
||||
}
|
||||
|
||||
func (a *App) Datasource(name string) string {
|
||||
config, exists := a.config.Databases[name]
|
||||
if !exists {
|
||||
@@ -306,7 +267,7 @@ func (a *App) Datasource(name string) string {
|
||||
// cmd/main.go
|
||||
//
|
||||
// cmd/database/migrations/*.sql
|
||||
func (a *App) Migrate(database embed.FS, dbName string) {
|
||||
func (a *App) Migrate(dbName string, database embed.FS) {
|
||||
dbConfig, exists := a.config.Databases[dbName]
|
||||
if !exists {
|
||||
slog.Error("database configuration not found", "name", dbName)
|
||||
|
||||
Reference in New Issue
Block a user