Documentation
¶
Index ¶
- func ExtractServiceName(projectRootPath, currentDir string) (string, error)
- func GoInstall(paths ...string) error
- func GoModTidy(ctx context.Context, rootPath string) error
- func HasCmdAndConfigs(dir string) (bool, bool, error)
- func IsDirExists(dir string) bool
- func IsFileExists(filePath string) bool
- func IsValidServiceName(projectRootPath, serviceName string) (bool, error)
- func ModulePath(filename string) (string, error)
- func ParseVCSUrl(repo string) (*url.URL, error)
- func ReplaceInFile(path, old, new string) error
- func ReplaceRegexInFile(path, pattern, replacement string) error
- func ReplaceTemplateInCurrentDir(rootDir, source, target string) (int, error)
- func SplitArgs(cmd *cobra.Command, args []string) (cmdArgs, programArgs []string)
- func Tree(path string, dir string)
- type GoCmd
- type ModuleInspector
- type Repo
- func (r *Repo) Clone(ctx context.Context) error
- func (r *Repo) CopyTo(ctx context.Context, to string, modPath string, ignores []string) error
- func (r *Repo) CopyToV2(ctx context.Context, to string, modPath string, ignores, replaces []string) error
- func (r *Repo) Path() string
- func (r *Repo) Pull(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractServiceName ¶
ExtractServiceName 从 currentDir 中提取服务名称,前提是 currentDir 位于 projectRootPath 之下,并且路径结构符合 app/{service}/service/cmd/server。
func HasCmdAndConfigs ¶
HasCmdAndConfigs 检查 dir(为空则使用工作目录)下是否存在 cmd 和 configs 目录。 返回 (hasCmd, hasConfigs, error)。
func IsDirExists ¶
func IsFileExists ¶
func IsValidServiceName ¶
IsValidServiceName 检查 serviceName 是否为 projectRootPath 下的有效服务名称,即 app/{serviceName}/service/cmd/server 存在,并且 app/{serviceName}/configs 目录存在。
func ModulePath ¶
ModulePath returns go module path.
func ParseVCSUrl ¶
ParseVCSUrl ref https://github.com/golang/go/blob/master/src/cmd/go/internal/vcs/vcs.go see https://go-review.googlesource.com/c/go/+/12226/ git url define https://git-scm.com/docs/git-clone#_git_urls
func ReplaceInFile ¶
ReplaceInFile 读取文件 `path`,将所有 `old` 替换为 `new`,并原子写回。 如果文件内容没有变化,不会修改文件时间。
func ReplaceRegexInFile ¶
ReplaceRegexInFile 使用正则 `pattern` 将匹配的部分替换为 `replacement` 并写回。 `pattern` 是普通的 Go 正则表达式。
func ReplaceTemplateInCurrentDir ¶
ReplaceTemplateInCurrentDir 遍历当前目录及子目录,替换指定的模板字符串。 返回被修改的文件数量和错误(如果有)。
Types ¶
type GoCmd ¶
type GoCmd struct {
Dir string // 工作目录
Env []string // 额外环境变量(追加到 os.Environ())
Timeout time.Duration // 若 >0,为每次执行设置超时
Stdin io.Reader
Stdout io.Writer // 若为 nil,Run 会使用 os.Stdout
Stderr io.Writer // 若为 nil,Run 会使用 os.Stderr
}
GoCmd 封装 go 命令执行。
func NewGoCmdWithTimeout ¶
NewGoCmdWithTimeout 返回一个带超时的 GoCmd。
func (*GoCmd) CombinedOutput ¶
CombinedOutput 执行并返回 stdout+stderr。
type ModuleInspector ¶
ModuleInspector 保存项目根目录和模块名。
func NewModuleInspectorFromGo ¶
func NewModuleInspectorFromGo(startDir string) (*ModuleInspector, error)
NewModuleInspectorFromGo 使用 `go list -m -json` 在 startDir(或当前目录)执行, 返回模块路径和项目根目录。若在 startDir 执行失败,会向上遍历父目录重试。
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo is git repository manager.