Files
lotr/cmd/beornextract/main.go
Christian Nieves ae55110082 meh
2023-07-12 22:28:24 -05:00

51 lines
1.0 KiB
Go

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/davecgh/go-spew/spew"
"github.com/squk/lotr/cmd/beornextract/types"
)
func main() {
fmt.Println("LOTR CARD PARSE")
f, err := bazel.Runfile(".")
if err != nil {
panic(err)
}
err = filepath.Walk(f,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
fmt.Println(path, info.Size())
return nil
})
if err != nil {
log.Println(err)
}
// Open our jsonFile
// jsonFile, err := os.Open("cmd/beornextract/data/Bot.Cards.json")
jsonFile, err := bazel.Runfile("cmd/beornextract/data/Bot.Cards.json")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Successfully Opened users.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
c := []types.HallOfBeornCard{}
json.Unmarshal(byteValue, &c)
spew.Dump(c)
}