utils

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// specifies the minimum version required to build the generated project.
	GeneratedGoVersionMinimum = "1.18"

	// specifies the preferred version.
	GeneratedGoVersionPreferred = "1.19"
)

Variables

View Source
var (
	ErrConvertArrayInterface     = errors.New("unable to convert to []interface{}")
	ErrConvertArrayString        = errors.New("unable to convert to []string")
	ErrConvertMapStringInterface = errors.New("unable to convert to map[string]interface{}")
	ErrConvertString             = errors.New("unable to convert to string")
)

Functions

func CloseFile

func CloseFile(file io.ReadCloser)

CloseFile safely closes a file handle.

func ContainsStringHelper

func ContainsStringHelper() template.FuncMap

ContainsStringHelper returns the function map for seeing if strings are contained within other strings.

func Glob

func Glob(pattern string) ([]string, error)

Glob adds double-star support to the core path/filepath Glob function. It's useful when your globs might have double-stars, but you're not sure.

func MustWrite

func MustWrite(n int, err error)

func QuoteStringHelper

func QuoteStringHelper() template.FuncMap

QuoteStringHelper returns the function map for quoting strings in templates.

func ReadStream

func ReadStream(fileName string) (io.ReadCloser, error)

func RemoveStringHelper

func RemoveStringHelper() template.FuncMap

RemoveStringHelper returns the function map for quoting strings in templates.

func TemplateHelpers

func TemplateHelpers() template.FuncMap

TemplateHelpers returns all of the template helpers in the utils package.

func ToArrayInterface

func ToArrayInterface(in interface{}) ([]interface{}, error)

ToArrayInterface attempts a conversion from an interface to an underlying array of interface type. Returns an error if the conversion is not possible.

func ToArrayString

func ToArrayString(in interface{}) ([]string, error)

ToArrayString attempts a conversion from an interface to an underlying array of string type. Returns an error if the conversion is not possible.

func ToFileName

func ToFileName(name string) string

ToFileName will convert a kebab-case string to a snake_case name appropriate to use in a go filename.

func ToMapStringInterface

func ToMapStringInterface(in interface{}) (map[string]interface{}, error)

ToMapStringInterface attempts a conversion from an interface to an underlying map string interface type. Returns an error if the conversion is not possible.

func ToPackageName

func ToPackageName(name string) string

ToPackageName will convert a kebab-case string to an all lower name appropriate for directory and package names.

func ToPascalCase

func ToPascalCase(name string) string

ToPascalCase will convert a kebab-case string to a PascalCase name appropriate to use as a go variable name.

func ToSnakeCase

func ToSnakeCase(name string) string

ToSnakeCase will convert a string to a snake case.

func ToString

func ToString(in interface{}) (string, error)

ToArrayInterface attempts a conversion from an interface to an underlying string type. Returns an error if the conversion is not possible.

func ToTitle

func ToTitle(in string) string

ToTitle replaces the strings.Title method, which is deprecated in go1.18. This is a helper method to make titling a string much more readable than the new methodology. TODO: use commented code below eventually. It returns different at this time but will eventually be deprecated.

Types

This section is empty.

Jump to

Keyboard shortcuts

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