I use MacOS Mojave with IntelliJ Ultimate 2018.2.
I wrote a go application that loads a config file from the directory of my project. I created an InitConfig()
function to load the JSON file into a struct. this is thee code of my Config.go
file
package main
import (
"github.com/tkanos/gonfig"
"log"
)
type Configuration struct {
WebServerPort int
DbName string
DbUser string
DbPassword string
DbPort int
CertFile string
KeyFile string
EnableHttps bool
}
var AppConfiguration Configuration
func InitConfig() {
AppConfiguration = Configuration{}
err := gonfig.GetConf(ExPath + "/config/config.json", &AppConfiguration)
if err != nil {
log.Fatalf("could not parse configuration file: %v",err)
}
}
I use a variable called ExPath
that contains the current directory of the running binary, I created it with the following code (Path.go):
package main
import (
"log"
"os"
"path/filepath"
)
var ExPath string
func InitPath() {
ex, err := os.Executable()
if err != nil {
log.Fatalf("could not get executable path: %v",err)
}
ExPath = filepath.Dir(ex)
}
when I try to run or debug the application, intellij is creating a directory where it compiles and runs the application, how can I tell it to also copy the json file?
when I try to run/debug my App I get:
could not parse configuration file: open /private/var/folders/60/qzt2pgs173s4j_r6lby_mw1c0000gn/T/config/config.json: no such file or directory
I checked and that directory really doesn't contain my config directory. so.. is there a way to let intellij know it should copy it before executing my project?
thanks!