Skip to content

Commit e9f07d7

Browse files
authored
Merge pull request #159 from arran4/fix/config-loading-issue
Allow running with environment variables only
2 parents 7fa95dd + bb44f9b commit e9f07d7

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ ENV GITHUB_SERVER=""
2121
ENV GITLAB_SERVER=""
2222
ENV LOCAL_GIT_PATH=/var/lib/gobookmarks/localgit
2323
ENV GOBM_ENV_FILE=/etc/gobookmarks/gobookmarks.env
24-
ENV GOBM_CONFIG_FILE=/etc/gobookmarks/config.json
2524
EXPOSE 8080
2625
EXPOSE 8443
2726
COPY gobookmarks /bin/gobookmarks

cmd/gobookmarks/main.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,14 @@ func (c *RootCommand) loadConfig() error {
145145
}
146146

147147
cfgSpecified := c.ConfigPath != "" || os.Getenv("GOBM_CONFIG_FILE") != ""
148-
if fileCfg, found, err := LoadConfigFile(configPath); err == nil {
149-
if found {
150-
MergeConfig(&c.cfg, fileCfg)
151-
}
152-
} else {
153-
if os.IsNotExist(err) && !cfgSpecified {
154-
log.Printf("config file %s not found", configPath)
155-
} else {
156-
return fmt.Errorf("unable to load config file %s: %w", configPath, err)
157-
}
148+
fileCfg, found, err := LoadConfigFile(configPath)
149+
if err != nil {
150+
return fmt.Errorf("unable to load config file %s: %w", configPath, err)
151+
}
152+
if found {
153+
MergeConfig(&c.cfg, fileCfg)
154+
} else if cfgSpecified {
155+
return fmt.Errorf("unable to load config file %s: not found", configPath)
158156
}
159157
return nil
160158
}

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func LoadConfigFile(path string) (Config, bool, error) {
4848
if err != nil {
4949
if os.IsNotExist(err) {
5050
log.Printf("config file %s not found", path)
51-
return c, false, err
51+
return c, false, nil
5252
}
5353
return c, false, fmt.Errorf("unable to read config file: %w", err)
5454
}

0 commit comments

Comments
 (0)