~sircmpwn/go-bare

524dbe963d1057822c757d925669e5481a134800 — John Mulligan 2 months ago 88a9d80
gen: only add errors import if type needs errors package

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>
1 files changed, 10 insertions(+), 3 deletions(-)

M cmd/gen/main.go
M cmd/gen/main.go => cmd/gen/main.go +10 -3
@@ 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
}