util

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NL = "\n"
)

NL defines a new line

Variables

This section is empty.

Functions

func Clean

func Clean(category string) error

Clean deletes all templates and removes the parent directory

func CreateIfNotExist

func CreateIfNotExist(file string) (*os.File, error)

CreateIfNotExist creates a file if it is not exists

func CreateTemplate

func CreateTemplate(category, name, content string) error

CreateTemplate writes template into file even it is exists

func FileExists

func FileExists(file string) bool

FileExists returns true if the specified file is exists

func FileNameWithoutExt

func FileNameWithoutExt(file string) string

FileNameWithoutExt returns a file name without suffix

func FindGoModPath

func FindGoModPath(dir string) (string, bool)

FindGoModPath returns the path in project where has file go.mod, it maybe return empty string if there is no go.mod file in project

func FindProjectPath

func FindProjectPath(loc string) (string, bool)

FindProjectPath returns the parent directory where has file go.mod in project

func GetGoctlHome

func GetGoctlHome() (string, error)

GetGoctlHome returns the path value of the goctl home where Join $HOME with .goctl

func GetHead

func GetHead(source string) string

GetHead returns a code head string with source filename

func GetTemplateDir

func GetTemplateDir(category string) (string, error)

GetTemplateDir returns the category path value in GoctlHome where could get it by GetGoctlHome

func Index

func Index(slice []string, item string) int

Index returns the index where the item equal,it will return -1 if mismatched

func InitTemplates

func InitTemplates(category string, templates map[string]string) error

InitTemplates creates template files GoctlHome where could get it by GetGoctlHome

func JoinPackages

func JoinPackages(pkgs ...string) string

JoinPackages calls strings.Join and returns

func LoadTemplate

func LoadTemplate(category, file, builtin string) (string, error)

LoadTemplate gets template content by the specified file

func MkdirIfNotExist

func MkdirIfNotExist(dir string) error

MkdirIfNotExist makes directories if the input path is not exists

func PathFromGoSrc

func PathFromGoSrc() (string, error)

PathFromGoSrc returns the path without slash where has been trim the prefix $GOPATH

func RemoveIfExist

func RemoveIfExist(filename string) error

RemoveIfExist deletes the specified file if it is exists

func RemoveOrQuit

func RemoveOrQuit(filename string) error

RemoveOrQuit deletes the specified file if read a permit command from stdin

func Title

func Title(s string) string

Title returns a string value with s[0] which has been convert into upper case that there are not empty input text

func ToCamelTable added in v1.0.8

func ToCamelTable(n stringx.String, cfg model.MultiModelCfg, merge string) string

func ToSource

func ToSource(n stringx.String, cfg model.MultiModelCfg) string

func Untitle

func Untitle(s string) string

Untitle returns a string value with s[0] which has been convert into lower case that there are not empty input text

Types

type DefaultTemplate

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

DefaultTemplate is a tool to provides the text/template operations

func With

func With(name string) *DefaultTemplate

With returns a instance of DefaultTemplate

func (*DefaultTemplate) Execute

func (t *DefaultTemplate) Execute(data interface{}) (*bytes.Buffer, error)

Execute returns the codes after the template executed

func (*DefaultTemplate) GoFmt

func (t *DefaultTemplate) GoFmt(format bool) *DefaultTemplate

GoFmt sets the value to goFmt and marks the generated codes will be formatted or not

func (*DefaultTemplate) Parse

func (t *DefaultTemplate) Parse(text string) *DefaultTemplate

Parse accepts a source template and returns DefaultTemplate

func (*DefaultTemplate) SaveTo

func (t *DefaultTemplate) SaveTo(data interface{}, path string, forceUpdate bool) error

SaveTo writes the codes to the target path

Directories

Path Synopsis
Package name provides methods to verify naming style and format naming style See the method IsNamingValid, FormatFilename
Package name provides methods to verify naming style and format naming style See the method IsNamingValid, FormatFilename

Jump to

Keyboard shortcuts

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