From c0e95df47f58b65b033e7b0540ccbaff84a15fa4 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Thu, 19 Jun 2025 08:46:56 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`feature?= =?UTF-8?q?/cli-auth`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @gocanto. * https://github.com/oullin/api/pull/33#issuecomment-2987047797 The following files were modified: * `boost/boost.go` * `cli/gate/guard.go` * `cli/main.go` * `database/seeder/main.go` * `main.go` * `pkg/cli/helpers.go` --- boost/boost.go | 4 ++++ cli/gate/guard.go | 1 + cli/main.go | 2 ++ database/seeder/main.go | 4 ++++ main.go | 1 + pkg/cli/helpers.go | 2 ++ 6 files changed, 14 insertions(+) diff --git a/boost/boost.go b/boost/boost.go index 7a57a29a..62b6de4c 100644 --- a/boost/boost.go +++ b/boost/boost.go @@ -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) @@ -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: " diff --git a/cli/gate/guard.go b/cli/gate/guard.go index 07e1bbb0..71226d8f 100644 --- a/cli/gate/guard.go +++ b/cli/gate/guard.go @@ -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, diff --git a/cli/main.go b/cli/main.go index 34a5de51..907e8142 100644 --- a/cli/main.go +++ b/cli/main.go @@ -15,6 +15,7 @@ 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") @@ -22,6 +23,7 @@ func init() { 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() diff --git a/database/seeder/main.go b/database/seeder/main.go index 40a5df84..c585c056 100644 --- a/database/seeder/main.go +++ b/database/seeder/main.go @@ -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() diff --git a/main.go b/main.go index 7a343890..626d0d7c 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/pkg/cli/helpers.go b/pkg/cli/helpers.go index 44383be8..beadce87 100644 --- a/pkg/cli/helpers.go +++ b/pkg/cli/helpers.go @@ -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