diff --git a/BUILD b/BUILD index d79f75e..6a7581a 100644 --- a/BUILD +++ b/BUILD @@ -1,13 +1,20 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary") - package( default_visibility = ["//visibility:public"], ) -go_binary( - name = "hello", - srcs = ["hello.go"], - deps = [ - "//cmd", - ] +load("@bazel_gazelle//:def.bzl", "gazelle") + +# gazelle:prefix github.com/squk/lotr +# gazelle:build_file_name BUILD +gazelle(name = "gazelle") + +gazelle( + name = "gazelle-update-repos", + args = [ + "-from_file=go.mod", + "-to_macro=deps.bzl%go_dependencies", + "-prune", + "-build_file_proto_mode=disable_global", + ], + command = "update-repos", ) diff --git a/WORKSPACE b/WORKSPACE index 6122903..0d161d2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,23 +1,47 @@ -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -# git_repository( -# name = "io_bazel_rules_go", -# remote = "https://github.com/bazelbuild/rules_go.git", -# branch = "master", -# ) - http_archive( name = "io_bazel_rules_go", - sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f", + sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + ], +) + +http_archive( + name = "bazel_gazelle", + sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", ], ) load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") + +############################################################ +# Define your own dependencies here using go_repository. +# Else, dependencies declared by rules_go/gazelle will be used. +# The first declaration of an external repository "wins". +############################################################ + +go_repository( + name = "com_github_davecgh_go_spew", + build_file_proto_mode = "disable_global", + importpath = "github.com/davecgh/go-spew", + sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", + version = "v1.1.1", +) + +load("//:deps.bzl", "go_dependencies") + +# gazelle:repository_macro deps.bzl%go_dependencies +go_dependencies() go_rules_dependencies() -go_register_toolchains(version = "1.19.3") +go_register_toolchains(version = "1.20.4") + +gazelle_dependencies() diff --git a/cmd/cmd.go b/cmd/cmd.go deleted file mode 100644 index fe06f8f..0000000 --- a/cmd/cmd.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "fmt" -) - -func main() { - fmt.Println("Hello World. Cmd") -} diff --git a/deps.bzl b/deps.bzl new file mode 100644 index 0000000..a8edf32 --- /dev/null +++ b/deps.bzl @@ -0,0 +1,2 @@ +def go_dependencies(): + pass diff --git a/extract/BUILD b/extract/BUILD new file mode 100644 index 0000000..67cb1e2 --- /dev/null +++ b/extract/BUILD @@ -0,0 +1,3 @@ +package( + default_visibility = ["//visibility:public"], +) diff --git a/extract/cmd/BUILD b/extract/cmd/BUILD new file mode 100644 index 0000000..dc2aa68 --- /dev/null +++ b/extract/cmd/BUILD @@ -0,0 +1,18 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "cmd_lib", + srcs = ["main.go"], + importpath = "github.com/squk/lotr/extract/cmd", + visibility = ["//visibility:private"], + deps = [ + "//extract/types", + "@com_github_davecgh_go_spew//spew", + ], +) + +go_binary( + name = "cmd", + embed = [":cmd_lib"], + visibility = ["//visibility:public"], +) diff --git a/extract/cmd/main.go b/extract/cmd/main.go new file mode 100644 index 0000000..3cfc02e --- /dev/null +++ b/extract/cmd/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "github.com/squk/lotr/extract/types" + "github.com/davecgh/go-spew/spew" +) + +func main() { + fmt.Println("LOTR CARD PARSE") + + + // Open our jsonFile + jsonFile, err := os.Open("users.json") + // if we os.Open returns an error then handle it + if err != nil { + fmt.Println(err) + } + 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.Card{} + json.Unmarshal(byteValue, &c) + spew.Dump(c) +} diff --git a/cmd/BUILD b/extract/types/BUILD similarity index 52% rename from cmd/BUILD rename to extract/types/BUILD index aaa1185..38e0032 100644 --- a/cmd/BUILD +++ b/extract/types/BUILD @@ -1,8 +1,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( - name ="cmd", - srcs = [ "cmd.go" ], + name = "types", + srcs = ["card.go"], + importpath = "github.com/squk/lotr/extract/types", visibility = ["//visibility:public"], - importpath= "github.com/squk/lotr/cmd" ) diff --git a/extract/types/card.go b/extract/types/card.go new file mode 100644 index 0000000..2b494fe --- /dev/null +++ b/extract/types/card.go @@ -0,0 +1,35 @@ +package extract + +type Card struct { + PackCode string `json:"pack_code"` + PackName string `json:"pack_name"` + IsOfficial bool `json:"is_official"` + TypeCode string `json:"type_code"` + TypeName string `json:"type_name"` + SphereCode string `json:"sphere_code"` + SphereName string `json:"sphere_name"` + Position int `json:"position"` + Code string `json:"code"` + Name string `json:"name"` + Traits string `json:"traits"` + Text string `json:"text"` + Flavor string `json:"flavor"` + IsUnique bool `json:"is_unique"` + Threat int `json:"threat"` + Willpower int `json:"willpower"` + Attack int `json:"attack"` + Defense int `json:"defense"` + Health int `json:"health"` + Quantity int `json:"quantity"` + DeckLimit int `json:"deck_limit"` + Illustrator string `json:"illustrator"` + Octgnid string `json:"octgnid"` + HasErrata bool `json:"has_errata"` + URL string `json:"url"` + Imagesrc string `json:"imagesrc"` + Versions []struct { + SetName string `json:"set_name"` + Year string `json:"year"` + URL string `json:"url"` + } `json:"versions"` +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e90d217 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/squk/lotr + +go 1.19 + +require github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b5e2922 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/hello.go b/hello.go deleted file mode 100644 index 6ffde47..0000000 --- a/hello.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "fmt" -) - -func main() { - fmt.Println("Hello World") -}