How to read resource files from the backend plugin?

I’d like to read resource files from the backend plugin implemented in Golang.
The files are in the same directory along with plugin.json and the front end javascript modules.

Just to see the current working directory, I tried below. It returned the directory where I started the grafana-server. So it doesn’t tell me where the plugin is. Is there anyway to find it?

func main() {
    path, err := os.Getwd()
    if err != nil {
        log.DefaultLogger.Error(err.Error())
    }
    log.DefaultLogger.Info(path)
}

The solution is to use os.Args[0]. It returns the full path of the plugin. Tested on MacOS and Linux. Hopefully it’s a full path on Windows.

Here is how to read plugin.json

import (
    "io/ioutil"
    "os"
    "path/filepath"
)

func main() {
    file, _ := ioutil.ReadFile(filepath.Join(filepath.Dir(os.Args[0]), "plugin.json"))
    log.DefaultLogger.Warn(string(file))
}