Skip to content

Commit

Permalink
change - add default configuration paths (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaerpour committed Jul 22, 2024
1 parent ff99bfd commit 42a097d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ of wireproxy by [@juev](https://github.com/juev).

# Usage
```
./wireproxy -c [path to config]
./wireproxy [-c path to config]
```

```
Expand All @@ -47,6 +47,7 @@ Arguments:
-h --help Print help information
-c --config Path of configuration file
Default paths: /etc/wireproxy/wireproxy.conf, $HOME/.config/wireproxy.conf
-s --silent Silent mode
-d --daemon Make wireproxy run in background
-i --info Specify the address and port for exposing health status
Expand Down
24 changes: 22 additions & 2 deletions cmd/wireproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
// an argument to denote that this process was spawned by -d
const daemonProcess = "daemon-process"

// default paths for wireproxy config file
var default_config_paths = []string {
"/etc/wireproxy/wireproxy.conf",
os.Getenv("HOME")+"/.config/wireproxy.conf",
}

var version = "1.0.8-dev"

func panicIfError(err error) {
Expand Down Expand Up @@ -51,6 +57,16 @@ func executablePath() string {
return programPath
}

// check if default config file paths exist
func configFilePath() (string, bool) {
for _, path := range default_config_paths {
if _, err := os.Stat(path); err == nil {
return path, true
}
}
return "", false
}

func lock(stage string) {
switch stage {
case "boot":
Expand Down Expand Up @@ -177,8 +193,12 @@ func main() {
}

if *config == "" {
fmt.Println("configuration path is required")
return
if path, config_exist := configFilePath(); config_exist {
*config = path
} else {
fmt.Println("configuration path is required")
return
}
}

if !*daemon {
Expand Down

0 comments on commit 42a097d

Please sign in to comment.