I have a Go application using a config.json
file to get some information. When doing a go run main.go
it works but when I'm compiling the application into an executable I have the error open config.json: no such file or directory
.
My code is:
func main() {
data, err := ioutil.ReadFile("./config.json")
check(err)
var config config
err = json.Unmarshal(data, &config)
check(err)
}
I also have tried ioutil.ReadFile("config.json")
and it does not work. check(err)
and the config
structure are in the main.go
, the problem does not come from here.
main.go
, config.json
and the executable are in the same directory.
What should I do to be able to use the config.json
file once the program is compiled?