Updating file path location search for config.json

Instead of looking for config.json form current directory when running the program, look for the config.json from the executable running directory.  This will allow for calling fail2rest executable from a service w/o getting the "failed to open config: config.json" error.
This commit is contained in:
Phillip Moore 2014-07-03 10:06:41 -05:00 committed by Sean DuBois
parent dec5d521b7
commit c5a2d036d7

View file

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"path"
"github.com/Sean-Der/fail2go"
"github.com/gorilla/mux"
"net/http"
@ -21,7 +22,11 @@ type ErrorBody struct {
var fail2goConn *fail2go.Conn
func main() {
file, fileErr := os.Open("config.json")
//Changing path of current running directory to path of running executable for finding the config.json file.
//This will allow the creation of a linux service to run fail2rest (ie: service fail2rest start/stop/status)
var filePath string = path.Dir(os.Args[0])
file, fileErr := os.Open(filePath + "/config.json")
if fileErr != nil {
fmt.Println("failed to open config:", fileErr)