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
|
||||
|
||||
ESI_CLIENT_ID=your-client-id
|
||||
ESI_REDIRECT_URI=http://localhost:3000/callback
|
||||
ESI_SCOPES=esi-planets.manage_planets.v1
|
||||
ESI_REFRESH_INTERVAL=P10M
|
||||
# EVE SSO client ID
|
||||
ESI_CLIENT_ID=your_esi_client_id_here
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
// Just a wrapper
|
||||
func (db *DBWrapper) Raw(sql string, args ...any) *gorm.DB {
|
||||
return db.db.Raw(sql, args...)
|
||||
}
|
||||
|
||||
7
main.go
7
main.go
@@ -18,19 +18,20 @@ var webhook wh.Webhook
|
||||
|
||||
func main() {
|
||||
// Add flag for generating .env.example
|
||||
help := flag.Bool("help", false, "Generate .env.example file")
|
||||
help := flag.Bool("h", false, "Show help")
|
||||
flag.Parse()
|
||||
|
||||
if *help {
|
||||
flag.PrintDefaults()
|
||||
if err := GenerateEnvExample(); err != nil {
|
||||
logger.Error("Failed to generate .env.example: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("Generated .env.example file successfully")
|
||||
logger.Info("Generated .env.example")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
logger.InitFlag()
|
||||
logger.Init(logger.ParseLevel(options.LogLevel))
|
||||
logger.Info("Starting Eve PI")
|
||||
|
||||
// Create SSO instance
|
||||
|
||||
26
options.go
26
options.go
@@ -23,17 +23,17 @@ func init() {
|
||||
|
||||
type Options struct {
|
||||
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"`
|
||||
RedirectURI string `env:"ESI_REDIRECT_URI" required:"true" description:"EVE SSO redirect URI"`
|
||||
ClientID string `env:"ESI_CLIENT_ID" description:"EVE SSO client ID"`
|
||||
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)"`
|
||||
|
||||
WebhookURL string `env:"WEBHOOK_URL" required:"true" description:"Webhook URL for notifications"`
|
||||
WebhookEmail string `env:"WEBHOOK_EMAIL" required:"true" description:"Webhook authentication email"`
|
||||
WebhookToken string `env:"WEBHOOK_TOKEN" required:"true" description:"Webhook authentication token"`
|
||||
WebhookURL string `env:"WEBHOOK_URL" description:"Webhook URL for notifications"`
|
||||
WebhookEmail string `env:"WEBHOOK_EMAIL" description:"Webhook authentication email"`
|
||||
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) {
|
||||
@@ -56,16 +56,13 @@ func LoadOptions() (Options, error) {
|
||||
}
|
||||
|
||||
envValue := os.Getenv(envKey)
|
||||
required := field.Tag.Get("required") == "true"
|
||||
defaultValue := field.Tag.Get("default")
|
||||
|
||||
if envValue == "" {
|
||||
if required {
|
||||
if defaultValue == "" {
|
||||
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
|
||||
@@ -111,12 +108,11 @@ func GenerateEnvExample() error {
|
||||
continue
|
||||
}
|
||||
|
||||
required := field.Tag.Get("required") == "true"
|
||||
defaultValue := field.Tag.Get("default")
|
||||
description := field.Tag.Get("description")
|
||||
|
||||
// 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=%s\n\n", envKey, exampleValue)
|
||||
@@ -132,7 +128,7 @@ func GenerateEnvExample() error {
|
||||
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 defaultValue != "" {
|
||||
return defaultValue
|
||||
|
||||
Reference in New Issue
Block a user