I am getting nil
for sampleFlags
in my debugger when attempting to read my file test.json
. I am not sure if it is a path issue or where the reader pointer is. How FetchFlags is triggered is by a handler
in server.go
that ultimately calls FetchFlags
.
flags.go
package flags
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type Flag struct {
Name string `json:"name"`
Category string `json:"category"`
Label string `json:"label"`
}
func FetchFlags() []Flag {
sampleFlags, _ := ioutil.ReadFile("test.json")
fmt.Printf("File contents: %s", sampleFlags)
var Flags []Flag
_ = json.Unmarshal(sampleFlags, &Flags)
return Flags
}
Structure:
/server
server.go
/package
/flags
flags.go
test.json
/pack_a
/pack_b