1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Fix some stuff

This commit is contained in:
Lukas Schulte Pelkum 2021-04-15 20:59:32 +02:00
parent 1792ef1c38
commit 681ee9f1d0
No known key found for this signature in database
GPG Key ID: 408DA7CA81DB885C
3 changed files with 29 additions and 30 deletions

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"os" "os"
"github.com/lus/pasty/internal/env" "github.com/lus/pasty/internal/config"
"github.com/lus/pasty/internal/shared" "github.com/lus/pasty/internal/shared"
"github.com/lus/pasty/internal/storage" "github.com/lus/pasty/internal/storage"
) )
@ -15,9 +15,9 @@ func main() {
panic("Invalid command line arguments") panic("Invalid command line arguments")
} }
// Load the optional .env file // Load the configuration
log.Println("Loading the optional .env file...") log.Println("Loading the application configuration...")
env.Load() config.Load()
// Create and initialize the first (from) driver // Create and initialize the first (from) driver
from, err := storage.GetDriver(shared.StorageType(os.Args[1])) from, err := storage.GetDriver(shared.StorageType(os.Args[1]))

View File

@ -4,7 +4,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/joho/godotenv"
"github.com/lus/pasty/internal/env" "github.com/lus/pasty/internal/env"
"github.com/lus/pasty/internal/shared" "github.com/lus/pasty/internal/shared"
) )
@ -64,39 +63,39 @@ var Current *Config
// Load loads the current config from environment variables and an optional .env file // Load loads the current config from environment variables and an optional .env file
func Load() { func Load() {
godotenv.Load() env.Load()
Current = &Config{ Current = &Config{
WebAddress: env.MustString("PASTY_WEB_ADDRESS", ":8080"), WebAddress: env.MustString("WEB_ADDRESS", ":8080"),
StorageType: shared.StorageType(strings.ToLower(env.MustString("PASTY_STORAGE_TYPE", "file"))), StorageType: shared.StorageType(strings.ToLower(env.MustString("STORAGE_TYPE", "file"))),
HastebinSupport: env.MustBool("PASTY_HASTEBIN_SUPPORT", false), HastebinSupport: env.MustBool("HASTEBIN_SUPPORT", false),
IDLength: env.MustInt("PASTY_ID_LENGTH", 6), IDLength: env.MustInt("ID_LENGTH", 6),
DeletionTokenLength: env.MustInt("PASTY_DELETION_TOKEN_LENGTH", 12), DeletionTokenLength: env.MustInt("DELETION_TOKEN_LENGTH", 12),
RateLimit: env.MustString("PASTY_RATE_LIMIT", "30-M"), RateLimit: env.MustString("RATE_LIMIT", "30-M"),
AutoDelete: &AutoDeleteConfig{ AutoDelete: &AutoDeleteConfig{
Enabled: env.MustBool("PASTY_AUTODELETE", false), Enabled: env.MustBool("AUTODELETE", false),
Lifetime: env.MustDuration("PASTY_AUTODELETE_LIFETIME", 720*time.Hour), Lifetime: env.MustDuration("AUTODELETE_LIFETIME", 720*time.Hour),
TaskInterval: env.MustDuration("PASTY_AUTODELETE_TASK_INTERVAL", 5*time.Minute), TaskInterval: env.MustDuration("AUTODELETE_TASK_INTERVAL", 5*time.Minute),
}, },
File: &FileConfig{ File: &FileConfig{
Path: env.MustString("PASTY_STORAGE_FILE_PATH", "./data"), Path: env.MustString("STORAGE_FILE_PATH", "./data"),
}, },
Postgres: &PostgresConfig{ Postgres: &PostgresConfig{
DSN: env.MustString("PASTY_STORAGE_POSTGRES_DSN", "postgres://pasty:pasty@localhost/pasty"), DSN: env.MustString("STORAGE_POSTGRES_DSN", "postgres://pasty:pasty@localhost/pasty"),
}, },
MongoDB: &MongoDBConfig{ MongoDB: &MongoDBConfig{
DSN: env.MustString("PASTY_STORAGE_MONGODB_CONNECTION_STRING", "mongodb://pasty:pasty@localhost/pasty"), DSN: env.MustString("STORAGE_MONGODB_CONNECTION_STRING", "mongodb://pasty:pasty@localhost/pasty"),
Database: env.MustString("PASTY_STORAGE_MONGODB_DATABASE", "pasty"), Database: env.MustString("STORAGE_MONGODB_DATABASE", "pasty"),
Collection: env.MustString("PASTY_STORAGE_MONGODB_COLLECTION", "pastes"), Collection: env.MustString("STORAGE_MONGODB_COLLECTION", "pastes"),
}, },
S3: &S3Config{ S3: &S3Config{
Endpoint: env.MustString("PASTY_STORAGE_S3_ENDPOINT", ""), Endpoint: env.MustString("STORAGE_S3_ENDPOINT", ""),
AccessKeyID: env.MustString("PASTY_STORAGE_S3_ACCESS_KEY_ID", ""), AccessKeyID: env.MustString("STORAGE_S3_ACCESS_KEY_ID", ""),
SecretAccessKey: env.MustString("PASTY_STORAGE_S3_SECRET_ACCESS_KEY", ""), SecretAccessKey: env.MustString("STORAGE_S3_SECRET_ACCESS_KEY", ""),
SecretToken: env.MustString("PASTY_STORAGE_S3_SECRET_TOKEN", ""), SecretToken: env.MustString("STORAGE_S3_SECRET_TOKEN", ""),
Secure: env.MustBool("PASTY_STORAGE_S3_SECURE", true), Secure: env.MustBool("STORAGE_S3_SECURE", true),
Region: env.MustString("PASTY_STORAGE_S3_REGION", ""), Region: env.MustString("STORAGE_S3_REGION", ""),
Bucket: env.MustString("PASTY_STORAGE_S3_BUCKET", "pasty"), Bucket: env.MustString("STORAGE_S3_BUCKET", "pasty"),
}, },
} }
} }

6
internal/env/env.go vendored
View File

@ -16,11 +16,11 @@ func Load() {
// MustString returns the content of the environment variable with the given key or the given fallback // MustString returns the content of the environment variable with the given key or the given fallback
func MustString(key, fallback string) string { func MustString(key, fallback string) string {
found := os.Getenv(static.EnvironmentVariablePrefix + key) value, found := os.LookupEnv(static.EnvironmentVariablePrefix + key)
if found == "" { if !found {
return fallback return fallback
} }
return found return value
} }
// MustBool uses MustString and parses it into a boolean // MustBool uses MustString and parses it into a boolean