Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Create shorten package #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ build:

.PHONY: test
test: vet
go test -count=1 -cover -coverprofile=coverage.out .
go test -count=1 -cover -coverprofile=coverage.out ./...
go tool cover -func=coverage.out

.PHONY: vet
vet:
go vet .
go vet ./...

.PHONY: regenerate
regenerate:
REGENERATE_TEST_OUTPUTS=true go test .
REGENERATE_TEST_OUTPUTS=true go test ./...

.PHONY: graph
graph:
Expand All @@ -34,4 +34,4 @@ vendor:

.PHONY: format
format:
goimports -w ./*go
goimports -w ./*go ./pkg/**/*go
22 changes: 11 additions & 11 deletions generate/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
// graph node. The latter can then be used to generate a dot file for debugging
// purposes.
func genNodeToGraphNode() error {
f := jen.NewFile("main")
f := jen.NewFile("shorten")
f.HeaderComment("Generated by generate/main.go. DO NOT EDIT.")

// Sort the keys in the dst map so that output is in stable order
Expand All @@ -27,16 +27,16 @@ func genNodeToGraphNode() error {

sort.Strings(dataKeys)

f.Func().Id("NodeToGraphNode").Params(
f.Func().Id("nodeToGraphNode").Params(
jen.Id("node").Qual(dstPath, "Node"),
).Op("*").Id("GraphNode").BlockFunc(
).Op("*").Id("graphNode").BlockFunc(
func(g *jen.Group) {
g.Id("gNode").Op(":=").Op("&").Id("GraphNode").Values(
g.Id("gNode").Op(":=").Op("&").Id("graphNode").Values(
jen.Id("Node").Op(":").Id("node"),
jen.Id("Edges").Op(":").Index().Op("*").Id("GraphEdge").Values(),
jen.Id("Edges").Op(":").Index().Op("*").Id("graphEdge").Values(),
)

g.Var().Id("child").Op("*").Id("GraphNode")
g.Var().Id("child").Op("*").Id("graphNode")

g.Switch(jen.Id("n").Op(":=").Id("node").Assert(jen.Id("type"))).BlockFunc(
func(g *jen.Group) {
Expand All @@ -51,13 +51,13 @@ func genNodeToGraphNode() error {
switch p := part.(type) {
case data.Node:
g.If(p.Field.Get("n").Op("!=").Nil()).Block(
jen.Id("child").Op("=").Id("NodeToGraphNode").
jen.Id("child").Op("=").Id("nodeToGraphNode").
Call(
p.Field.Get("n"),
),
jen.Id("gNode").Dot("Edges").Op("=").Append(
jen.Id("gNode").Dot("Edges"),
jen.Op("&").Id("GraphEdge").Values(
jen.Op("&").Id("graphEdge").Values(
jen.Id("Dest").Op(":").Id("child"),
jen.Id("Relationship").Op(":").Lit(p.Name),
),
Expand All @@ -69,13 +69,13 @@ func genNodeToGraphNode() error {
jen.List(jen.Id("_"), jen.Id("obj")).
Op(":=").Range().Add(p.Field.Get("n")),
).Block(
jen.Id("child").Op("=").Id("NodeToGraphNode").
jen.Id("child").Op("=").Id("nodeToGraphNode").
Call(
jen.Id("obj"),
),
jen.Id("gNode").Dot("Edges").Op("=").Append(
jen.Id("gNode").Dot("Edges"),
jen.Op("&").Id("GraphEdge").Values(
jen.Op("&").Id("graphEdge").Values(
jen.Id("Dest").Op(":").Id("child"),
jen.Id("Relationship").Op(":").Lit(p.Name),
),
Expand Down Expand Up @@ -103,7 +103,7 @@ func genNodeToGraphNode() error {
},
)

f.Save("../graph_generated.go")
f.Save("../shorten/graph_generated.go")

return nil
}
Loading