Refine shit a little more
This commit is contained in:
33
.env.example
33
.env.example
@@ -1,11 +1,28 @@
|
|||||||
DB_PATH=db.sqlite
|
# EVE PI Configuration
|
||||||
|
# Database file path
|
||||||
|
DB_PATH=eve-pi.db
|
||||||
|
|
||||||
|
# HTTP server port
|
||||||
HTTP_SERVER_PORT=3000
|
HTTP_SERVER_PORT=3000
|
||||||
|
|
||||||
ESI_CLIENT_ID=your-client-id
|
# EVE SSO client ID
|
||||||
ESI_REDIRECT_URI=http://localhost:3000/callback
|
ESI_CLIENT_ID=your_esi_client_id_here
|
||||||
ESI_SCOPES=esi-planets.manage_planets.v1
|
|
||||||
ESI_REFRESH_INTERVAL=P10M
|
# EVE SSO redirect URI
|
||||||
|
ESI_REDIRECT_URI=your_esi_redirect_uri_here
|
||||||
|
|
||||||
|
# EVE SSO scopes (space-separated)
|
||||||
|
ESI_SCOPES=esi-planets.manage_planets.v1
|
||||||
|
|
||||||
|
# Webhook URL for notifications
|
||||||
|
WEBHOOK_URL=your_webhook_url_here
|
||||||
|
|
||||||
|
# Webhook authentication email
|
||||||
|
WEBHOOK_EMAIL=your_webhook_email_here
|
||||||
|
|
||||||
|
# Webhook authentication token
|
||||||
|
WEBHOOK_TOKEN=your_webhook_token_here
|
||||||
|
|
||||||
|
# Logging level (debug, info, warning, error)
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
WEBHOOK_URL=https://your-webhook-url.com
|
|
||||||
WEBHOOK_EMAIL=your-webhook-email
|
|
||||||
WEBHOOK_TOKEN=your-webhook-token
|
|
||||||
1
db.go
1
db.go
@@ -47,7 +47,6 @@ func GetDB() (DB, error) {
|
|||||||
return &DBWrapper{db: db}, nil
|
return &DBWrapper{db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just a wrapper
|
|
||||||
func (db *DBWrapper) Raw(sql string, args ...any) *gorm.DB {
|
func (db *DBWrapper) Raw(sql string, args ...any) *gorm.DB {
|
||||||
return db.db.Raw(sql, args...)
|
return db.db.Raw(sql, args...)
|
||||||
}
|
}
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -18,19 +18,20 @@ var webhook wh.Webhook
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Add flag for generating .env.example
|
// Add flag for generating .env.example
|
||||||
help := flag.Bool("help", false, "Generate .env.example file")
|
help := flag.Bool("h", false, "Show help")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *help {
|
if *help {
|
||||||
|
flag.PrintDefaults()
|
||||||
if err := GenerateEnvExample(); err != nil {
|
if err := GenerateEnvExample(); err != nil {
|
||||||
logger.Error("Failed to generate .env.example: %v", err)
|
logger.Error("Failed to generate .env.example: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
logger.Info("Generated .env.example file successfully")
|
logger.Info("Generated .env.example")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.InitFlag()
|
logger.Init(logger.ParseLevel(options.LogLevel))
|
||||||
logger.Info("Starting Eve PI")
|
logger.Info("Starting Eve PI")
|
||||||
|
|
||||||
// Create SSO instance
|
// Create SSO instance
|
||||||
|
|||||||
26
options.go
26
options.go
@@ -23,17 +23,17 @@ func init() {
|
|||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
DBPath string `env:"DB_PATH" default:"eve-pi.db" description:"Database file path"`
|
DBPath string `env:"DB_PATH" default:"eve-pi.db" description:"Database file path"`
|
||||||
Port string `env:"HTTP_SERVER_PORT" default:"3000" description:"HTTP server port"`
|
Port string `env:"HTTP_SERVER_PORT" default:"3000" description:"HTTP server port"`
|
||||||
|
|
||||||
ClientID string `env:"ESI_CLIENT_ID" required:"true" description:"EVE SSO client ID"`
|
ClientID string `env:"ESI_CLIENT_ID" description:"EVE SSO client ID"`
|
||||||
RedirectURI string `env:"ESI_REDIRECT_URI" required:"true" description:"EVE SSO redirect URI"`
|
RedirectURI string `env:"ESI_REDIRECT_URI" default:"http://localhost:3000/callback" description:"EVE SSO redirect URI"`
|
||||||
Scopes []string `env:"ESI_SCOPES" default:"esi-planets.manage_planets.v1" description:"EVE SSO scopes (space-separated)"`
|
Scopes []string `env:"ESI_SCOPES" default:"esi-planets.manage_planets.v1" description:"EVE SSO scopes (space-separated)"`
|
||||||
|
|
||||||
WebhookURL string `env:"WEBHOOK_URL" required:"true" description:"Webhook URL for notifications"`
|
WebhookURL string `env:"WEBHOOK_URL" description:"Webhook URL for notifications"`
|
||||||
WebhookEmail string `env:"WEBHOOK_EMAIL" required:"true" description:"Webhook authentication email"`
|
WebhookEmail string `env:"WEBHOOK_EMAIL" description:"Webhook authentication email"`
|
||||||
WebhookToken string `env:"WEBHOOK_TOKEN" required:"true" description:"Webhook authentication token"`
|
WebhookToken string `env:"WEBHOOK_TOKEN" description:"Webhook authentication token"`
|
||||||
|
|
||||||
LogLevel string `env:"LOG_LEVEL" default:"info" description:"Logging level (debug, info, warning, error)"`
|
LogLevel string `env:"LOG_LEVEL" default:"info" description:"Logging level (dump, trace, debug, info, warning, error)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadOptions() (Options, error) {
|
func LoadOptions() (Options, error) {
|
||||||
@@ -56,16 +56,13 @@ func LoadOptions() (Options, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
envValue := os.Getenv(envKey)
|
envValue := os.Getenv(envKey)
|
||||||
required := field.Tag.Get("required") == "true"
|
|
||||||
defaultValue := field.Tag.Get("default")
|
defaultValue := field.Tag.Get("default")
|
||||||
|
|
||||||
if envValue == "" {
|
if envValue == "" {
|
||||||
if required {
|
if defaultValue == "" {
|
||||||
return Options{}, fmt.Errorf("required environment variable %s is not set", envKey)
|
return Options{}, fmt.Errorf("required environment variable %s is not set", envKey)
|
||||||
}
|
}
|
||||||
if defaultValue != "" {
|
envValue = defaultValue
|
||||||
envValue = defaultValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the field value based on its type
|
// Set the field value based on its type
|
||||||
@@ -111,12 +108,11 @@ func GenerateEnvExample() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
required := field.Tag.Get("required") == "true"
|
|
||||||
defaultValue := field.Tag.Get("default")
|
defaultValue := field.Tag.Get("default")
|
||||||
description := field.Tag.Get("description")
|
description := field.Tag.Get("description")
|
||||||
|
|
||||||
// Generate example value
|
// Generate example value
|
||||||
exampleValue := generateExampleValue(field.Name, envKey, defaultValue, required)
|
exampleValue := generateExampleValue(field.Name, envKey, defaultValue)
|
||||||
|
|
||||||
content += fmt.Sprintf("# %s\n", description)
|
content += fmt.Sprintf("# %s\n", description)
|
||||||
content += fmt.Sprintf("%s=%s\n\n", envKey, exampleValue)
|
content += fmt.Sprintf("%s=%s\n\n", envKey, exampleValue)
|
||||||
@@ -132,7 +128,7 @@ func GenerateEnvExample() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateExampleValue(fieldName, envKey, defaultValue string, required bool) string {
|
func generateExampleValue(fieldName, envKey, defaultValue string) string {
|
||||||
// If there's a default value, use it
|
// If there's a default value, use it
|
||||||
if defaultValue != "" {
|
if defaultValue != "" {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
|||||||
Reference in New Issue
Block a user