helper

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Funcs = template.FuncMap{
		"lower":     strings.ToLower,
		"hasPrefix": strings.HasPrefix,
		"hasSuffix": strings.HasSuffix,
		"upper":     strings.ToUpper,
		"trim":      strings.Trim,
		"replace":   strings.ReplaceAll,
		"hasField":  HasField,
		"pascal":    Pascal,
		"base":      filepath.Base,
		"pkgName":   code.PkgShortName,
		"join":      Join,
		"quote":     Quote,
		"joinQuote": JoinQuote,
	}
)

Functions

func Camel

func Camel(s string) string

Camel converts the given name into a camelCase.

user_info  => userInfo
full_name  => fullName
user_id    => userID
full-admin => fullAdmin

func CatchGraphError

func CatchGraphError(err *error)

func CheckDir

func CheckDir(dir string) error

CheckDir checks the given dir and reports if there are any VCS conflicts.

func CheckGraphError

func CheckGraphError(err error, msg string, args ...any)

func EscapePathElements

func EscapePathElements(path string) string

EscapePathElements breaks apart a path, and looks at each element. If it's not a path parameter, eg, {param}, it will URL-escape the element.

func Expect

func Expect(cond bool, msg string, args ...any)

Expect panics if the condition is false.

func HasField

func HasField(v any, name string) bool

HasField determines if a struct has a field with the given name.

func InStrSlice

func InStrSlice(haystack []string, needle string) bool

func IsBuildError

func IsBuildError(err error) bool

IsBuildError reports if the given error is an error from the Go command (e.g. syntax error).

func Join

func Join(a []string, sep string) string

Join is a wrapper around strings.Join to provide consistent output.

func JoinQuote

func JoinQuote(a []string, sep string) string

func NormalizePkg

func NormalizePkg(pkg string) (nlpkg string, err error)

func ParseT

func ParseT(path string, templates embed.FS, funcs template.FuncMap) *gen.Template

func Pascal

func Pascal(s string) string

Pascal converts the given name into a PascalCase.

user_info 	=> UserInfo
full_name 	=> FullName
user_id   	=> UserID
full-admin	=> FullAdmin

func Quote

func Quote(v any) any

Quote only strings.

func Snake

func Snake(s string) string

Snake converts the given struct or field name into a snake_case.

Username => username
FullName => full_name
HTTPCode => http_code

Types

type Assets

type Assets struct {
	// contains filtered or unexported fields
}

func (*Assets) Add

func (a *Assets) Add(path string, content []byte)

func (*Assets) AddDir

func (a *Assets) AddDir(path string)

func (Assets) Format

func (a Assets) Format() error

Format runs "goimports" on all Assets.

func (Assets) ModTidy

func (a Assets) ModTidy(root string) error

func (Assets) Write

func (a Assets) Write() error

Write files and dirs in the Assets.

type GraphError

type GraphError struct {
	// contains filtered or unexported fields
}

func (GraphError) Error

func (p GraphError) Error() string

type Template

type Template struct {
	*template.Template
	FuncMap template.FuncMap
}

Template wraps the standard template.Template to provide additional functionality for ent extensions.

func MustParse

func MustParse(t *Template, err error) *Template

MustParse is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil.

func NewTemplate

func NewTemplate(name string) *Template

NewTemplate creates an empty template with the standard codegen functions.

func (*Template) AddParseTree

func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)

AddParseTree adds the given parse tree to the template.

func (*Template) Funcs

func (t *Template) Funcs(funcMap template.FuncMap) *Template

Funcs merges the given funcMap with the template functions.

func (*Template) Parse

func (t *Template) Parse(text string) (*Template, error)

Parse parses text as a template body for t.

func (*Template) ParseDir

func (t *Template) ParseDir(path string) (*Template, error)

ParseDir walks on the given dir path and parses the given matches with aren't Go files.

func (*Template) ParseFS

func (t *Template) ParseFS(fsys fs.FS, patterns ...string) (*Template, error)

ParseFS is like ParseFiles or ParseGlob but reads from the file system fsys instead of the host operating system's file system.

func (*Template) ParseFiles

func (t *Template) ParseFiles(filenames ...string) (*Template, error)

ParseFiles parses a list of files as templates and associate them with t. Each file can be a standalone template.

func (*Template) ParseGlob

func (t *Template) ParseGlob(pattern string) (*Template, error)

ParseGlob parses the files that match the given pattern as templates and associate them with t.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL