The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/plugins/codegen/package_json.go

33 lines
662 B

package codegen
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
type PackageJSON struct {
Version string `json:"version"`
}
// Opens the package.json file in the provided directory and returns a struct that represents its contents
func OpenPackageJSON(dir string) (PackageJSON, error) {
f, err := os.Open(filepath.Clean(dir + "/package.json"))
if err != nil {
return PackageJSON{}, err
}
defer func() {
if err := f.Close(); err != nil {
log.Println("error closing package.json", err)
}
}()
jsonObj := PackageJSON{}
if err := json.NewDecoder(f).Decode(&jsonObj); err != nil {
return PackageJSON{}, err
}
return jsonObj, nil
}