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

@@ -5,6 +5,7 @@ import (
"unicode"
)
// IsUpperCase returns true if the rune in A-Z
func IsUpperCase(r rune) bool {
if r >= 'A' && r <= 'Z' {
return true
@@ -12,6 +13,7 @@ func IsUpperCase(r rune) bool {
return false
}
// IsLowerCase returns true if the rune in a-z
func IsLowerCase(r rune) bool {
if r >= 'a' && r <= 'z' {
return true
@@ -19,6 +21,7 @@ func IsLowerCase(r rune) bool {
return false
}
// ToSnakeCase returns a copy string by converting camel case into snake case
func ToSnakeCase(s string) string {
var out []rune
for index, r := range s {
@@ -44,6 +47,7 @@ func ToSnakeCase(s string) string {
return string(out)
}
// ToCamelCase returns a copy string by converting snake case into camel case
func ToCamelCase(s string) string {
s = ToLower(s)
out := []rune{}
@@ -66,6 +70,7 @@ func ToCamelCase(s string) string {
return string(out)
}
// ToLowerCase converts rune into lower case
func ToLowerCase(r rune) rune {
dx := 'A' - 'a'
if IsUpperCase(r) {
@@ -73,6 +78,8 @@ func ToLowerCase(r rune) rune {
}
return r
}
// ToUpperCase converts rune into upper case
func ToUpperCase(r rune) rune {
dx := 'A' - 'a'
if IsLowerCase(r) {
@@ -81,6 +88,7 @@ func ToUpperCase(r rune) rune {
return r
}
// ToLower returns a copy string by converting it into lower
func ToLower(s string) string {
var out []rune
for _, r := range s {
@@ -89,6 +97,7 @@ func ToLower(s string) string {
return string(out)
}
// ToUpper returns a copy string by converting it into upper
func ToUpper(s string) string {
var out []rune
for _, r := range s {
@@ -97,13 +106,7 @@ func ToUpper(s string) string {
return string(out)
}
func LowerFirst(s string) string {
if len(s) == 0 {
return s
}
return ToLower(s[:1]) + s[1:]
}
// UpperFirst converts s[0] into upper case
func UpperFirst(s string) string {
if len(s) == 0 {
return s
@@ -111,6 +114,7 @@ func UpperFirst(s string) string {
return ToUpper(s[:1]) + s[1:]
}
// UnExport converts the first letter into lower case
func UnExport(text string) bool {
var flag bool
str := strings.Map(func(r rune) rune {

View File

@@ -13,6 +13,7 @@ import (
"github.com/tal-tech/go-zero/tools/goctl/util"
)
// MaybeCreateFile creates file if not exists
func MaybeCreateFile(dir, subdir, file string) (fp *os.File, created bool, err error) {
logx.Must(util.MkdirIfNotExist(path.Join(dir, subdir)))
fpath := path.Join(dir, subdir, file)
@@ -26,10 +27,12 @@ func MaybeCreateFile(dir, subdir, file string) (fp *os.File, created bool, err e
return
}
// WrapErr wraps an error with message
func WrapErr(err error, message string) error {
return errors.New(message + ", " + err.Error())
}
// Copy calls io.Copy if the source file and destination file exists
func Copy(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
@@ -55,6 +58,7 @@ func Copy(src, dst string) (int64, error) {
return nBytes, err
}
// ComponentName returns component name for typescript
func ComponentName(api *spec.ApiSpec) string {
name := api.Service.Name
if strings.HasSuffix(name, "-api") {
@@ -63,12 +67,14 @@ func ComponentName(api *spec.ApiSpec) string {
return name + "Components"
}
// WriteIndent writes tab spaces
func WriteIndent(writer io.Writer, indent int) {
for i := 0; i < indent; i++ {
fmt.Fprint(writer, "\t")
}
}
// RemoveComment filters comment content
func RemoveComment(line string) string {
var commentIdx = strings.Index(line, "//")
if commentIdx >= 0 {