CreateAdmin โ CLI Tool to Seed an Admin UserThe CreateAdmin CLI command creates a new admin user in the database. It's used to bootstrap the first superuser for your system, often run once during setup or testing.
go run main.go --name="Alice Admin" --email="[email protected]" --password="securepass123"
All flags are required. If any are missing, the tool exits with an error.
mainfunc main()
Entry point that parses flags, validates input, connects to the DB, hashes the password, and inserts the admin user.
| Flag | Type | Description |
|---|---|---|
--name |
string | Full name of the admin |
--email |
string | Email address (must be unique) |
--password |
string | Plaintext password (will be hashed) |
Parse CLI Flags
Uses the Go flag package to get user input.
Validate Required Input
Exits with log.Fatal if any flag is missing.
Load Configuration
Loads environment variables using config.LoadConfig(".").
Initialize DB Connection
Creates a PostgreSQL connection pool using pgxpool.New.