1 Star 2 Fork 5

北京小程科技有限公司 / 常量和模型生成工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
constant_item.go 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
package golang
import (
"fmt"
"strings"
"gitee.com/xiaochengtech/unified-structure/src/common"
)
// 默认的常量字段格式
func constantItemDefault(ctx common.Context) string {
varName := fmt.Sprintf("%s%s", ctx.File.Name, ctx.Field.Name)
varType := convertBasicType(ctx.GetFieldVarType())
if varType == "string" {
return fmt.Sprintf("%s = \"%s\" // %s", varName, ctx.Field.Value, ctx.Field.GetComment())
} else if (strings.Contains(varType, "int") && varType != "interface{}") || strings.Contains(varType, "float") {
return fmt.Sprintf("%s = %s(%s) // %s", varName, varType, ctx.Field.Value, ctx.Field.GetComment())
} else {
return fmt.Sprintf("%s = %s // %s", varName, ctx.Field.Value, ctx.Field.GetComment())
}
}
// IOTA常量第一个字段格式
func constantItemIotaFirst(ctx common.Context) string {
varName := fmt.Sprintf("%s%s", ctx.File.Name, ctx.Field.Name)
varType := convertBasicType(ctx.GetFieldVarType())
var offset string
if ctx.File.Iota.Offset > 0 {
offset = fmt.Sprintf("+ %d", ctx.File.Iota.Offset)
} else if ctx.File.Iota.Offset < 0 {
offset = fmt.Sprintf("%d", ctx.File.Iota.Offset)
} else {
offset = ""
}
return fmt.Sprintf("%s %s = iota %s // %s", varName, varType, offset, ctx.Field.GetComment())
}
// IOTA常量非第一个的字段格式
func constantItemIotaOther(ctx common.Context) string {
varName := fmt.Sprintf("%s%s", ctx.File.Name, ctx.Field.Name)
return fmt.Sprintf("%s // %s", varName, ctx.Field.GetComment())
}
Go
1
https://gitee.com/xiaochengtech/unified-structure.git
git@gitee.com:xiaochengtech/unified-structure.git
xiaochengtech
unified-structure
常量和模型生成工具
2b090969dddc

搜索帮助

53164aa7 5694891 3bd8fe86 5694891