pathx

package
v0.0.0-...-2482490 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NL = "\n"
)
View Source
const (
	RpcServiceFieldPrefix = "Service"
)

Variables

This section is empty.

Functions

func Clean

func Clean(category string) error

Clean deletes all templates and removes the parent directory.

func Copy

func Copy(src, dest string) error

func CreateDirectoryIfNotExist

func CreateDirectoryIfNotExist(path string) error

CreateDirectoryIfNotExist 生成目录

func CreateFileIfNotExist

func CreateFileIfNotExist(path string) (*os.File, error)

CreateFileIfNotExist 生成文件

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 FindGoModPath

func FindGoModPath(dir string) (string, bool)

FindGoModPath returns the path in project where has file go.mod, it returns 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 GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the cache dit of goctl.

func GetCtlHome

func GetCtlHome() (home string, err error)

GetCtlHome returns the path value of the goctl, the default path is ~/.goctl, if the path has been set by calling the RegisterGoctlHome method, the user-defined path refers to.

func GetDefaultCtlHome

func GetDefaultCtlHome() (string, error)

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

func GetGitHome

func GetGitHome() (string, error)

GetGitHome returns the git home of goctl.

func GetTemplateDir

func GetTemplateDir(category string) (string, error)

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

func InitTemplates

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

InitTemplates creates template files GoctlHome where could get it by GetGoctlHome.

func IsTemplateVariable

func IsTemplateVariable(text string) bool

IsTemplateVariable 函数会返回 true,如果文本是一个模板变量 文本必须以点号开头,并且是一个有效的模板。

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 MaybeCreateFile

func MaybeCreateFile(dir, subdir, file string) (fp *os.File, created bool, err error)

MaybeCreateFile creates file if not exists

func MkdirIfNotExist

func MkdirIfNotExist(dir string) error

MkdirIfNotExist makes directories if the input path is not exists

func NewFileBuild

func NewFileBuild(tp *TemplateData, filePath string) error

NewFileBuild 基于template模板生成文件

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

func RegisterGoctlHome(home string)

RegisterGoctlHome register goctl home path.

func SameFile

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 TemplateVariable

func TemplateVariable(text string) string

TemplateVariable 函数返回模板的变量名。

Types

type RpcMethod

type RpcMethod struct {
	StructFieldName string
	Name            string
	RequestType     string
	ResponseType    string
}

func (RpcMethod) FuncStr

func (this RpcMethod) FuncStr() string

type TemplateData

type TemplateData struct {
	Content []byte

	PackageName string
	ProtoName   string
	FieldName   string

	ModelPath string
	ModelName string

	RpcFilePath string
	RpcMethods  []RpcMethod
}

func NewTemplate

func NewTemplate(content []byte) *TemplateData

func (*TemplateData) ExtractRPCMethods

func (this *TemplateData) ExtractRPCMethods() []RpcMethod

func (*TemplateData) Parse

func (this *TemplateData) Parse() (*template.Template, error)

func (*TemplateData) SetFieldName

func (this *TemplateData) SetFieldName(s string) *TemplateData

func (*TemplateData) SetModelName

func (this *TemplateData) SetModelName(s string) *TemplateData

func (*TemplateData) SetModelPath

func (this *TemplateData) SetModelPath(s string) *TemplateData

func (*TemplateData) SetPackage

func (this *TemplateData) SetPackage(s string) *TemplateData

func (*TemplateData) SetProtoName

func (this *TemplateData) SetProtoName(s string) *TemplateData

func (*TemplateData) SetRpcFilePath

func (this *TemplateData) SetRpcFilePath(s string) *TemplateData

Jump to

Keyboard shortcuts

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