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

51 lines
2.0 KiB
Go
Raw Normal View History

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-07 18:46:19 +03:00
LogLevel string `default:"info" split_words:"true"`
WebAddress string `default:":8080" split_words:"true"`
StorageDriver string `default:"sqlite" split_words:"true"`
HastebinSupport bool `default:"false" split_words:"true"`
IDLength int `default:"6" split_words:"true"`
IDCharacters string `default:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" split_words:"true"`
ModificationTokens bool `default:"true" split_words:"true"`
ModificationTokenMaster string `split_words:"true"`
ModificationTokenLength int `default:"12" split_words:"true"`
ModificationTokenCharacters string `default:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" split_words:"true"`
RateLimit string `default:"30-M" split_words:"true"`
LengthCap int `default:"50000" split_words:"true"`
AutoDelete *AutoDeleteConfig `split_words:"true"`
Reports *ReportConfig
Postgres *PostgresConfig
2021-04-15 21:15:42 +03:00
}
type AutoDeleteConfig struct {
2023-06-07 18:46:19 +03:00
Enabled bool `default:"false"`
Lifetime time.Duration `default:"720h"`
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-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
}