如何在Go lang中读取config.json?

I have used the following code in filLib.go:

func LoadConfiguration(filename string) (Configuration, error) {
    bytes, err := ioutil.ReadFile(filename)
    if err != nil {
        return Configuration{}, err
    }

    var c Configuration
    err = json.Unmarshal(bytes, &c)
    if err != nil {
        return Configuration{}, err
    }

    return c, nil
}

But ioutil.ReadFile(filename) return *os.PathError.

Both the files config.json and filLib.go are in same folder.

The issue might be with the filename you're providing. Below is the code sample that working fine for me.

func loadConfig() {
    var AppConfig Conf
    raw, err := ioutil.ReadFile("conf/conf.json")
    if err != nil {
       log.Println("Error occured while reading config")
       return
    }
    json.Unmarshal(raw, &AppConfig)
}

The path of *.go file is not directly relevant to the working directory of the executing compiled code. Verify where your code thinks it actually is (compare to where you think it should be :).

import(
  "os" 
  "fmt"
  "log"
)

func main() {
  dir, err := os.Getwd()
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(dir)
}