feat: remove env prefix for docker

pull/761/head
Xhofe 2022-03-13 17:01:45 +08:00
parent c51dc4594d
commit bb017c5f6d
5 changed files with 28 additions and 20 deletions

View File

@ -11,4 +11,4 @@ VOLUME /opt/alist/data/
WORKDIR /opt/alist/ WORKDIR /opt/alist/
COPY --from=builder /app/bin/alist ./ COPY --from=builder /app/bin/alist ./
EXPOSE 5244 EXPOSE 5244
CMD [ "./alist" ] CMD [ "./alist -docker" ]

View File

@ -54,7 +54,13 @@ func InitConf() {
} }
func confFromEnv() { func confFromEnv() {
if err := env.Parse(conf.Conf); err != nil { prefix := "ALIST_"
if conf.Docker {
prefix = ""
}
if err := env.Parse(conf.Conf, env.Options{
Prefix: prefix,
}); err != nil {
log.Fatalf("load config from env error: %s", err.Error()) log.Fatalf("load config from env error: %s", err.Error())
} }
} }

View File

@ -30,6 +30,7 @@ func init() {
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode") flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info") flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.BoolVar(&conf.Password, "password", false, "print current password") flag.BoolVar(&conf.Password, "password", false, "print current password")
flag.BoolVar(&conf.Docker, "docker", false, "is using docker")
flag.Parse() flag.Parse()
InitLog() InitLog()
} }

View File

@ -1,37 +1,37 @@
package conf package conf
type Database struct { type Database struct {
Type string `json:"type" env:"A_LIST_DB_TYPE"` Type string `json:"type" env:"DB_TYPE"`
User string `json:"user" env:"A_LIST_DB_USER"` Host string `json:"host" env:"DB_HOST"`
Password string `json:"password" env:"A_LIST_DB_PASS"` Port int `json:"port" env:"DB_PORT"`
Host string `json:"host" env:"A_LIST_DB_HOST"` User string `json:"user" env:"DB_USER"`
Port int `json:"port" env:"A_LIST_DB_PORT"` Password string `json:"password" env:"DB_PASS"`
Name string `json:"name" env:"A_LIST_DB_NAME"` Name string `json:"name" env:"DB_NAME"`
TablePrefix string `json:"table_prefix" env:"A_LIST_DB_TABLE_PREFIX"` DBFile string `json:"db_file" env:"DB_FILE"`
DBFile string `json:"db_file" env:"A_LIST_DB_FILE"` TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
SslMode string `json:"ssl_mode" env:"A_LIST_SLL_MODE"` SslMode string `json:"ssl_mode" env:"DB_SLL_MODE"`
} }
type Scheme struct { type Scheme struct {
Https bool `json:"https" env:"A_LIST_HTTPS"` Https bool `json:"https" env:"HTTPS"`
CertFile string `json:"cert_file" env:"A_LIST_CERT"` CertFile string `json:"cert_file" env:"CERT_FILE"`
KeyFile string `json:"key_file" env:"A_LIST_KEY"` KeyFile string `json:"key_file" env:"KEY_FILE"`
} }
type CacheConfig struct { type CacheConfig struct {
Expiration int64 `json:"expiration" env:"A_LIST_EXPIRATION"` Expiration int64 `json:"expiration" env:"CACHE_EXPIRATION"`
CleanupInterval int64 `json:"cleanup_interval" env:"A_LIST_CLEANUP_INTERVAL"` CleanupInterval int64 `json:"cleanup_interval" env:"CLEANUP_INTERVAL"`
} }
type Config struct { type Config struct {
Force bool `json:"force"` Force bool `json:"force"`
Address string `json:"address" env:"A_LIST_ADDR"` Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"A_LIST_PORT"` Port int `json:"port" env:"PORT"`
Assets string `json:"assets" env:"A_LIST_ASSETS"` Assets string `json:"assets" env:"ASSETS"`
Database Database `json:"database"` Database Database `json:"database"`
Scheme Scheme `json:"scheme"` Scheme Scheme `json:"scheme"`
Cache CacheConfig `json:"cache"` Cache CacheConfig `json:"cache"`
TempDir string `json:"temp_dir" env:"A_LIST_TEMP_DIR"` TempDir string `json:"temp_dir" env:"TEMP_DIR"`
} }
func DefaultConfig() *Config { func DefaultConfig() *Config {

View File

@ -24,6 +24,7 @@ var (
Debug bool Debug bool
Version bool Version bool
Password bool Password bool
Docker bool
DB *gorm.DB DB *gorm.DB
Cache *cache.Cache Cache *cache.Cache