util

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 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 added in v1.0.22

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 added in v1.0.22

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 added in v1.0.7

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 added in v1.1.0

func FindProjectPath(loc string) (string, bool)

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

func GetGoctlHome added in v1.0.29

func GetGoctlHome() (string, error)

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

func GetHead added in v1.0.7

func GetHead(source string) string

GetHead returns a code head string with source filename

func GetTemplateDir added in v1.0.22

func GetTemplateDir(category string) (string, error)

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

func Index added in v1.1.0

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

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

func InitTemplates added in v1.0.22

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 added in v1.0.22

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 MustTempDir added in v1.2.2

func MustTempDir() string

MustTempDir creates a temporary directory

func PathFromGoSrc

func PathFromGoSrc() (string, error)

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

func ReadLink(name string) (string, error)

ReadLink returns the destination of the named symbolic link recursively.

func RegisterGoctlHome added in v1.1.10

func RegisterGoctlHome(home string)

RegisterGoctlHome register goctl home path

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 SafeString added in v1.2.0

func SafeString(in string) string

SafeString converts the input string into a safe naming style in golang

func SameFile added in v1.2.2

func SameFile(path1, path2 string) (bool, error)

SameFile compares the between path if the same path, it maybe the same path in case case-ignore, such as: /Users/go_zero and /Users/Go_zero, as far as we know, this case maybe appear on macOS and Windows.

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 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 added in v1.1.5

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

DefaultTemplate is a tool to provides the text/template operations

func With added in v1.0.7

func With(name string) *DefaultTemplate

With returns a instance of DefaultTemplate

func (*DefaultTemplate) Execute added in v1.1.5

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

Execute returns the codes after the template executed

func (*DefaultTemplate) GoFmt added in v1.1.5

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 added in v1.1.5

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

Parse accepts a source template and returns DefaultTemplate

func (*DefaultTemplate) SaveTo added in v1.1.5

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