(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package config
import (
"fmt"
"path/filepath"
"sort"
"strings"
"time"
"allaboutapps.dev/aw/go-starter/internal/util"
)
// 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)
const DatabaseMigrationTable = "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.
var DatabaseMigrationFolder = filepath.Join(util.GetProjectRootDir(), "/migrations")
type Database struct {
Host string
Port int
Username string
Password string `json:"-"` // sensitive
Database string
AdditionalParams map[string]string `json:"additionalParams,omitempty"` // Optional additional connection parameters mapped into the connection string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
}
// ConnectionString generates a connection string to be passed to sql.Open or equivalents, assuming Postgres syntax
func (c Database) ConnectionString() string {
var builder strings.Builder
builder.WriteString(fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", c.Host, c.Port, c.Username, c.Password, c.Database))
if _, ok := c.AdditionalParams["sslmode"]; !ok {
builder.WriteString(" sslmode=disable")
}
if len(c.AdditionalParams) > 0 {
params := make([]string, 0, len(c.AdditionalParams))
for param := range c.AdditionalParams {
params = append(params, param)
}
sort.Strings(params)
for _, param := range params {
fmt.Fprintf(&builder, " %s=%s", param, c.AdditionalParams[param])
}
}
return builder.String()
}