~sircmpwn/public-inbox

go-bare: gen: only add errors import if type needs errors package v1 APPLIED

John Mulligan: 1
 gen: only add errors import if type needs errors package

 1 files changed, 10 insertions(+), 3 deletions(-)
#360414 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/15531/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH go-bare] gen: only add errors import if type needs errors package Export this patch

The errors package will only be imported if its needed later in the
code. Currently this is only if an enum is generated.

Signed-off-by: John Mulligan <phlogistonjohn@asynchrono.us>
---
 cmd/gen/main.go | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/cmd/gen/main.go b/cmd/gen/main.go
index 9d2e106..a4cb296 100644
--- a/cmd/gen/main.go
+++ b/cmd/gen/main.go
@@ -21,7 +21,9 @@ package {{.package}}
// Code generated by go-bare/cmd/gen, DO NOT EDIT.

import (
{{- if .schema.NeedErrors }}
	"errors"
{{- end }}
	"git.sr.ht/~sircmpwn/go-bare"
)

@@ -248,9 +250,10 @@ func parseArgs() *Config {
}

type Types struct {
	UserTypes []*schema.UserDefinedType
	Enums     []*schema.UserDefinedEnum
	Unions    []*schema.UserDefinedType
	UserTypes  []*schema.UserDefinedType
	Enums      []*schema.UserDefinedEnum
	Unions     []*schema.UserDefinedType
	NeedErrors bool
}

func parseSchema(path string, skip map[string]bool) Types {
@@ -286,5 +289,9 @@ func parseSchema(path string, skip map[string]bool) Types {
		}
	}

	if len(types.Enums) > 0 {
		types.NeedErrors = true
	}

	return types
}
-- 
2.26.2
builds.sr.ht
go-bare/patches/.build.yml: SUCCESS in 29s

[gen: only add errors import if type needs errors package][0] from [John Mulligan][1]

[0]: https://lists.sr.ht/~sircmpwn/public-inbox/patches/15531
[1]: mailto:phlogistonjohn@asynchrono.us

✓ #360414 SUCCESS go-bare/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/360414
Thanks!

To git@git.sr.ht:~sircmpwn/go-bare
   524dbe9..88a9d80  master -> master