mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 14:52:46 +08:00
CI: Make pkg/build its own module, remove unused Grafana modules in go.mo… (#89243)
* Make pkg/build its own module, remove unused Grafana modules in go.mod/go.sum * fix go.work format * log errors on file close errors
This commit is contained in:
33
pkg/plugins/codegen/package_json.go
Normal file
33
pkg/plugins/codegen/package_json.go
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user