Code optimized (#523)

* optimized markdown generator

* optimized markdown generator

* optimized markdown generator

* add more comment

* add comment

* add comment

* add comments for rpc tool

* add comments for model tool

* add comments for model tool

* add comments for model tool

* add comments for config tool

* add comments for config tool

* add comments

* add comments

* add comments

* add comments

* add comment

* remove rpc main head info

* add comment

* optimized

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
kingxt
2021-02-26 16:11:47 +08:00
committed by GitHub
parent ef146cf5ba
commit e6ef1fca12
104 changed files with 651 additions and 375 deletions

View File

@@ -15,10 +15,12 @@ const (
goModeIdentifier = "go.mod"
)
// JoinPackages calls strings.Join and returns
func JoinPackages(pkgs ...string) string {
return strings.Join(pkgs, pkgSep)
}
// MkdirIfNotExist makes directories if the input path is not exists
func MkdirIfNotExist(dir string) error {
if len(dir) == 0 {
return nil
@@ -31,6 +33,7 @@ func MkdirIfNotExist(dir string) error {
return nil
}
// PathFromGoSrc returns the path whihout slash where has been trim the prefix $GOPATH
func PathFromGoSrc() (string, error) {
dir, err := os.Getwd()
if err != nil {
@@ -48,6 +51,8 @@ func PathFromGoSrc() (string, error) {
return dir[len(parent)+1:], nil
}
// 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 FindGoModPath(dir string) (string, bool) {
absDir, err := filepath.Abs(dir)
if err != nil {
@@ -80,6 +85,7 @@ func FindGoModPath(dir string) (string, bool) {
return "", false
}
// FindProjectPath returns the parent directory where has file go.mod in project
func FindProjectPath(loc string) (string, bool) {
var dir string
if strings.IndexByte(loc, '/') == 0 {