Skip to content

Commit

Permalink
Add config path next to executable
Browse files Browse the repository at this point in the history
Searching for config only in cwd isn't intuitive for end users.
  • Loading branch information
shemanaev committed Oct 9, 2022
1 parent b51dddd commit 45975f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OPDS 1.1 and web server for `.inpx` libraries with full-text search.
### Standalone

Download the latest release.
Download [`inpxer-example.toml`](./inpxer-example.toml), rename to `inpxer.toml`, put near executable and edit to your liking.
Download [`inpxer-example.toml`](./inpxer-example.toml), rename to `inpxer.toml`, put next to executable (or current working directory) and edit to your liking.

Import data:
```shell
Expand Down
15 changes: 13 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package config

import (
"os"
"path"
"path/filepath"

"github.com/pelletier/go-toml/v2"
)

const configFilename = "inpxer.toml"

type MyConfig struct {
Language string `toml:"language"`
Title string `toml:"title"`
Expand All @@ -25,8 +29,15 @@ type Converter struct {

func Load() (*MyConfig, error) {
configFiles := []string{
"inpxer.toml",
"/data/inpxer.toml",
configFilename,
path.Join("/data", configFilename),
}

exe, err := os.Executable()
if err == nil {
exePath := filepath.Dir(exe)
exeConf := filepath.Join(exePath, configFilename)
configFiles = append(configFiles, exeConf)
}

var configFile string
Expand Down

0 comments on commit 45975f2

Please sign in to comment.