Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boost/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func MakeDbConnection(env *env.Environment) *database.Connection {
return dbConn
}

// MakeLogs creates and returns a logging driver configured with the provided environment settings.
// Panics if log files cannot be opened.
func MakeLogs(env *env.Environment) *llogs.Driver {
lDriver, err := llogs.MakeFilesLogs(env)

Expand All @@ -56,6 +58,8 @@ func MakeLogs(env *env.Environment) *llogs.Driver {
return &lDriver
}

// MakeEnv constructs an env.Environment from a map of environment variable values, validating each component and panicking if any validation fails.
// All string values are trimmed of whitespace before assignment. Returns the fully validated environment configuration.
func MakeEnv(values map[string]string, validate *pkg.Validator) *env.Environment {
errorSufix := "Environment: "

Expand Down
1 change: 1 addition & 0 deletions cli/gate/guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Guard struct {
reader *bufio.Reader
}

// MakeGuard creates and returns a Guard initialized with the provided token and a buffered reader for standard input.
func MakeGuard(token auth.Token) Guard {
return Guard{
token: token,
Expand Down
2 changes: 2 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
var guard gate.Guard
var environment *env.Environment

// init loads environment secrets from a .env file and initializes the global environment and authentication guard.
func init() {
secrets, _ := boost.Spark("./../.env")

environment = secrets
guard = gate.MakeGuard(environment.App.Credentials)
}

// main is the entry point for the CLI application, handling user authentication and presenting a menu-driven interface for further actions.
func main() {
cli.ClearScreen()

Expand Down
4 changes: 4 additions & 0 deletions database/seeder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import (

var environment *env.Environment

// init loads environment variables from the .env file and assigns them to the global environment variable.
func init() {
secrets, _ := boost.Spark("./.env")

environment = secrets
}

// main orchestrates the database seeding process, performing truncation and seeding of all entities in a structured and concurrent manner.
// It initializes environment configuration, establishes database and logging connections, and coordinates the seeding of users, posts, categories, tags, comments, likes, post-category and post-tag relationships, post views, and newsletters.
// The function ensures proper sequencing and concurrency for dependent and independent seeding tasks, and outputs progress and status messages to the CLI.
func main() {
cli.ClearScreen()

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
validator = validate
}

// main initializes application dependencies, registers user routes, verifies database connectivity, and starts the HTTP server. Panics if the server fails to start.
func main() {
dbConnection := boost.MakeDbConnection(environment)
logs := boost.MakeLogs(environment)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
)

// ClearScreen attempts to clear the terminal screen by running the "clear" command.
// If the command fails, it logs an error message.
func ClearScreen() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
Expand Down
Loading