From a05ba67a36d1da338f2046422355fc23fe27371e Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 1 Dec 2022 10:48:01 -0800 Subject: [PATCH] go2: rm -rf --- d2ast/d2ast_test.go | 3 +- d2chaos/d2chaos.go | 3 +- d2compiler/compile.go | 3 +- d2graph/d2graph.go | 3 +- d2graph/serde.go | 2 +- d2layouts/d2dagrelayout/layout.go | 3 +- d2layouts/d2elklayout/layout.go | 3 +- d2layouts/d2sequence/layout.go | 3 +- d2oracle/edit.go | 3 +- d2oracle/edit_test.go | 3 +- d2parser/parse.go | 3 +- d2renderers/d2svg/d2svg.go | 3 +- d2target/d2target.go | 3 +- go.mod | 4 +-- go.sum | 4 +-- lib/go2/go2.go | 60 ------------------------------- lib/textmeasure/markdown.go | 3 +- 17 files changed, 31 insertions(+), 78 deletions(-) delete mode 100644 lib/go2/go2.go diff --git a/d2ast/d2ast_test.go b/d2ast/d2ast_test.go index 883a68018..8c447cd4f 100644 --- a/d2ast/d2ast_test.go +++ b/d2ast/d2ast_test.go @@ -13,10 +13,11 @@ import ( "oss.terrastruct.com/diff" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2parser" - "oss.terrastruct.com/d2/lib/go2" ) func TestRange(t *testing.T) { diff --git a/d2chaos/d2chaos.go b/d2chaos/d2chaos.go index 56b8c40b4..8b6c74f5e 100644 --- a/d2chaos/d2chaos.go +++ b/d2chaos/d2chaos.go @@ -6,12 +6,13 @@ import ( "strings" "time" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2oracle" "oss.terrastruct.com/d2/d2target" - "oss.terrastruct.com/d2/lib/go2" ) func GenDSL(maxi int) (_ string, err error) { diff --git a/d2compiler/compile.go b/d2compiler/compile.go index b5de7915b..775ced5ec 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -8,12 +8,13 @@ import ( "strconv" "strings" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2parser" "oss.terrastruct.com/d2/d2target" - "oss.terrastruct.com/d2/lib/go2" ) // TODO: should Parse even be exported? guess not. IR should contain list of files and diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 694e88e2e..fa5dc3bc6 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2parser" @@ -15,7 +17,6 @@ import ( "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/d2themes" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/textmeasure" ) diff --git a/d2graph/serde.go b/d2graph/serde.go index bfaac7c80..e5a8b1fbc 100644 --- a/d2graph/serde.go +++ b/d2graph/serde.go @@ -3,7 +3,7 @@ package d2graph import ( "encoding/json" - "oss.terrastruct.com/d2/lib/go2" + "oss.terrastruct.com/util-go/go2" ) type SerializedGraph struct { diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 672871226..ad8a67d84 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -13,10 +13,11 @@ import ( "oss.terrastruct.com/xdefer" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/log" "oss.terrastruct.com/d2/lib/shape" diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 2df4c65be..8a075206b 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -15,10 +15,11 @@ import ( "oss.terrastruct.com/xdefer" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/label" ) diff --git a/d2layouts/d2sequence/layout.go b/d2layouts/d2sequence/layout.go index 359463892..6e15061d3 100644 --- a/d2layouts/d2sequence/layout.go +++ b/d2layouts/d2sequence/layout.go @@ -6,9 +6,10 @@ import ( "math" "sort" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/shape" ) diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 5e943056e..c2cf70d67 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -11,13 +11,14 @@ import ( "oss.terrastruct.com/xrand" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2compiler" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2parser" "oss.terrastruct.com/d2/d2target" - "oss.terrastruct.com/d2/lib/go2" ) func Create(g *d2graph.Graph, key string) (_ *d2graph.Graph, newKey string, err error) { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 84090a4e0..58dc8f97e 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -13,12 +13,13 @@ import ( "oss.terrastruct.com/diff" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2compiler" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2oracle" "oss.terrastruct.com/d2/d2target" - "oss.terrastruct.com/d2/lib/go2" ) // TODO: make assertions less specific diff --git a/d2parser/parse.go b/d2parser/parse.go index 3c99dc1eb..d8351dcbc 100644 --- a/d2parser/parse.go +++ b/d2parser/parse.go @@ -9,8 +9,9 @@ import ( "unicode" "unicode/utf8" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2ast" - "oss.terrastruct.com/d2/lib/go2" ) type ParseOptions struct { diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 64aa75759..692db2cca 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -20,12 +20,13 @@ import ( "github.com/alecthomas/chroma/lexers" "github.com/alecthomas/chroma/styles" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2renderers/d2fonts" "oss.terrastruct.com/d2/d2renderers/d2latex" "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/lib/color" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/shape" "oss.terrastruct.com/d2/lib/textmeasure" diff --git a/d2target/d2target.go b/d2target/d2target.go index 3f749fa87..9c2dd2c9b 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -5,9 +5,10 @@ import ( "net/url" "strings" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2themes" "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/go2" "oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/shape" ) diff --git a/go.mod b/go.mod index 53766670c..14cfc5097 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/stretchr/testify v1.8.1 github.com/yuin/goldmark v1.5.3 go.uber.org/multierr v1.8.0 - golang.org/x/exp v0.0.0-20221126150942-6ab00d035af9 golang.org/x/image v0.1.0 golang.org/x/net v0.2.0 golang.org/x/text v0.4.0 @@ -25,7 +24,7 @@ require ( nhooyr.io/websocket v1.8.7 oss.terrastruct.com/cmdlog v0.0.0-20221201100934-012c01b3431c oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541 - oss.terrastruct.com/util-go v0.0.0-20221201180807-58edfec77805 + oss.terrastruct.com/util-go v0.0.0-20221201184644-70a234206a9a oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f oss.terrastruct.com/xdefer v0.0.0-20221017222355-6f3b6e4d1557 oss.terrastruct.com/xjson v0.0.0-20221018000420-4986731c4c4a @@ -57,6 +56,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.7.0 // indirect golang.org/x/crypto v0.3.0 // indirect + golang.org/x/exp v0.0.0-20221126150942-6ab00d035af9 // indirect golang.org/x/sys v0.2.0 // indirect golang.org/x/term v0.2.0 // indirect google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect diff --git a/go.sum b/go.sum index f6562ad91..3462d23b8 100644 --- a/go.sum +++ b/go.sum @@ -802,8 +802,8 @@ oss.terrastruct.com/cmdlog v0.0.0-20221201100934-012c01b3431c h1:C1DDLzj2NrVi1YJ oss.terrastruct.com/cmdlog v0.0.0-20221201100934-012c01b3431c/go.mod h1:C8u/lYTvQWc1xC7rHpgFfpScfQC4NMeGGMmlKVZZUXM= oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541 h1:I9B1O1IJ6spivIQxbFRZmbhAwVeLwrcQRR1JbYUOvrI= oss.terrastruct.com/diff v1.0.2-0.20221116222035-8bf4dd3ab541/go.mod h1:ags2QDy/T6jr69hT6bpmAmhr2H98n9o8Atf3QlUJPiU= -oss.terrastruct.com/util-go v0.0.0-20221201180807-58edfec77805 h1:DaMNXVEa+ZapP2U2gBVehedPdFsT7GGsGM+d7erCGAY= -oss.terrastruct.com/util-go v0.0.0-20221201180807-58edfec77805/go.mod h1:AN5T0bJ89/Q6ZebXIdPGpwAqVhK9PkDpgygWJaT2JzQ= +oss.terrastruct.com/util-go v0.0.0-20221201184644-70a234206a9a h1:4+7aYDQhnJa+lM0VpQ9xn4EsyBc5T09ry7d2YXnVekM= +oss.terrastruct.com/util-go v0.0.0-20221201184644-70a234206a9a/go.mod h1:l3FJb1Ne4egFfJRbdLJAk4hLZ61nr9kMm0thv2+SvCw= oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f h1:7voRCwKM7TZkTo9u7hj+uV/zXoVB8czWrTq6MVIh3dg= oss.terrastruct.com/xcontext v0.0.0-20221018000442-50fdafb12f4f/go.mod h1:Y0coTLsWwX0q3a+/Ndq797t+vWyxm42T49Ik3bzaDKY= oss.terrastruct.com/xdefer v0.0.0-20221017222355-6f3b6e4d1557 h1:rPbhJbN1q7B4tnppSPoAMwq0t6Pk5SrQDQ5S6uoNNHg= diff --git a/lib/go2/go2.go b/lib/go2/go2.go deleted file mode 100644 index 20482efa2..000000000 --- a/lib/go2/go2.go +++ /dev/null @@ -1,60 +0,0 @@ -// Package go2 contains general utility helpers that should've been in Go. Maybe they'll be in Go 2.0. -package go2 - -import ( - "hash/fnv" - "math" - - "golang.org/x/exp/constraints" -) - -func Pointer[T any](v T) *T { - return &v -} - -func Min[T constraints.Ordered](a, b T) T { - if a < b { - return a - } - return b -} - -func Max[T constraints.Ordered](a, b T) T { - if a > b { - return a - } - return b -} - -func StringToIntHash(s string) int { - h := fnv.New32a() - h.Write([]byte(s)) - return int(h.Sum32()) -} - -func Contains[T comparable](els []T, el T) bool { - for _, el2 := range els { - if el2 == el { - return true - } - } - return false -} - -func Filter[T any](els []T, fn func(T) bool) []T { - out := []T{} - for _, el := range els { - if fn(el) { - out = append(out, el) - } - } - return out -} - -func IntMax(x, y int) int { - return int(math.Max(float64(x), float64(y))) -} - -func IntMin(x, y int) int { - return int(math.Min(float64(x), float64(y))) -} diff --git a/lib/textmeasure/markdown.go b/lib/textmeasure/markdown.go index e625e9597..846c0955f 100644 --- a/lib/textmeasure/markdown.go +++ b/lib/textmeasure/markdown.go @@ -10,8 +10,9 @@ import ( goldmarkHtml "github.com/yuin/goldmark/renderer/html" "golang.org/x/net/html" + "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2renderers/d2fonts" - "oss.terrastruct.com/d2/lib/go2" ) var markdownRenderer goldmark.Markdown