2021-04-15 21:15:42 +03:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2023-06-07 18:46:19 +03:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
2021-04-15 21:15:42 +03:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2023-06-17 19:55:55 +03:00
|
|
|
LogLevel string `default:"info" split_words:"true"`
|
|
|
|
Address string `default:":8080" split_words:"true"`
|
|
|
|
StorageDriver string `default:"sqlite" split_words:"true"`
|
|
|
|
PasteIDLength int `default:"6" split_words:"true"`
|
|
|
|
PasteIDCharset string `default:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" split_words:"true"`
|
|
|
|
ModificationTokensEnabled bool `default:"true" split_words:"true"`
|
|
|
|
ModificationTokenMaster string `split_words:"true"`
|
|
|
|
ModificationTokenLength int `default:"12" split_words:"true"`
|
|
|
|
ModificationTokenCharset string `default:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" split_words:"true"`
|
|
|
|
RateLimit string `default:"30-M" split_words:"true"`
|
|
|
|
PasteLengthCap int `default:"50000" split_words:"true"`
|
|
|
|
Cleanup *CleanupConfig
|
2023-06-17 19:35:26 +03:00
|
|
|
Reports *ReportConfig
|
|
|
|
Postgres *PostgresConfig
|
|
|
|
SQLite *SQLiteConfig
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|
|
|
|
|
2023-06-17 19:55:55 +03:00
|
|
|
type CleanupConfig struct {
|
|
|
|
Enabled bool `default:"false"`
|
|
|
|
PasteLifetime time.Duration `default:"720h" split_words:"true"`
|
|
|
|
TaskInterval time.Duration `default:"5m" split_words:"true"`
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|
|
|
|
|
2023-06-07 18:46:19 +03:00
|
|
|
type ReportConfig struct {
|
|
|
|
Enabled bool `default:"false" split_words:"true"`
|
|
|
|
WebhookURL string `split_words:"true"`
|
|
|
|
WebhookToken string `split_words:"true"`
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type PostgresConfig struct {
|
2023-06-07 18:46:19 +03:00
|
|
|
DSN string `default:"postgres://pasty:pasty@localhost/pasty"`
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|
|
|
|
|
2023-06-13 02:22:05 +03:00
|
|
|
type SQLiteConfig struct {
|
|
|
|
File string `default:":memory:"`
|
|
|
|
}
|
|
|
|
|
2023-06-07 18:46:19 +03:00
|
|
|
func Load() (*Config, error) {
|
|
|
|
_ = godotenv.Overload()
|
|
|
|
cfg := new(Config)
|
|
|
|
if err := envconfig.Process("pasty", cfg); err != nil {
|
|
|
|
return nil, err
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|
2023-06-07 18:46:19 +03:00
|
|
|
return cfg, nil
|
2021-04-15 21:15:42 +03:00
|
|
|
}
|