Skip to content

Commit

Permalink
feat: remove env prefix for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 13, 2022
1 parent c51dc45 commit bb017c5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ VOLUME /opt/alist/data/
WORKDIR /opt/alist/
COPY --from=builder /app/bin/alist ./
EXPOSE 5244
CMD [ "./alist" ]
CMD [ "./alist -docker" ]
8 changes: 7 additions & 1 deletion bootstrap/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ func InitConf() {
}

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())
}
}
1 change: 1 addition & 0 deletions bootstrap/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.BoolVar(&conf.Password, "password", false, "print current password")
flag.BoolVar(&conf.Docker, "docker", false, "is using docker")
flag.Parse()
InitLog()
}
36 changes: 18 additions & 18 deletions conf/config.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package conf

type Database struct {
Type string `json:"type" env:"A_LIST_DB_TYPE"`
User string `json:"user" env:"A_LIST_DB_USER"`
Password string `json:"password" env:"A_LIST_DB_PASS"`
Host string `json:"host" env:"A_LIST_DB_HOST"`
Port int `json:"port" env:"A_LIST_DB_PORT"`
Name string `json:"name" env:"A_LIST_DB_NAME"`
TablePrefix string `json:"table_prefix" env:"A_LIST_DB_TABLE_PREFIX"`
DBFile string `json:"db_file" env:"A_LIST_DB_FILE"`
SslMode string `json:"ssl_mode" env:"A_LIST_SLL_MODE"`
Type string `json:"type" env:"DB_TYPE"`
Host string `json:"host" env:"DB_HOST"`
Port int `json:"port" env:"DB_PORT"`
User string `json:"user" env:"DB_USER"`
Password string `json:"password" env:"DB_PASS"`
Name string `json:"name" env:"DB_NAME"`
DBFile string `json:"db_file" env:"DB_FILE"`
TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
SslMode string `json:"ssl_mode" env:"DB_SLL_MODE"`
}

type Scheme struct {
Https bool `json:"https" env:"A_LIST_HTTPS"`
CertFile string `json:"cert_file" env:"A_LIST_CERT"`
KeyFile string `json:"key_file" env:"A_LIST_KEY"`
Https bool `json:"https" env:"HTTPS"`
CertFile string `json:"cert_file" env:"CERT_FILE"`
KeyFile string `json:"key_file" env:"KEY_FILE"`
}

type CacheConfig struct {
Expiration int64 `json:"expiration" env:"A_LIST_EXPIRATION"`
CleanupInterval int64 `json:"cleanup_interval" env:"A_LIST_CLEANUP_INTERVAL"`
Expiration int64 `json:"expiration" env:"CACHE_EXPIRATION"`
CleanupInterval int64 `json:"cleanup_interval" env:"CLEANUP_INTERVAL"`
}

type Config struct {
Force bool `json:"force"`
Address string `json:"address" env:"A_LIST_ADDR"`
Port int `json:"port" env:"A_LIST_PORT"`
Assets string `json:"assets" env:"A_LIST_ASSETS"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
Assets string `json:"assets" env:"ASSETS"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
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 {
Expand Down
1 change: 1 addition & 0 deletions conf/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
Debug bool
Version bool
Password bool
Docker bool

DB *gorm.DB
Cache *cache.Cache
Expand Down

0 comments on commit bb017c5

Please sign in to comment.