11 Star 11 Fork 0

Gitee 极速下载/goa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/goadesign/goa
克隆/下载
types.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
Nitin 提交于 2018-12-06 13:43 . [BREAKING] dsl package refactor (#1913)
package codegen
import (
"fmt"
"sort"
"strings"
"goa.design/goa/expr"
)
// GoNativeTypeName returns the Go built-in type corresponding to the given
// primitive type. GoNativeType panics if t is not a primitive type.
func GoNativeTypeName(t expr.DataType) string {
switch t.Kind() {
case expr.BooleanKind:
return "bool"
case expr.IntKind:
return "int"
case expr.Int32Kind:
return "int32"
case expr.Int64Kind:
return "int64"
case expr.UIntKind:
return "uint"
case expr.UInt32Kind:
return "uint32"
case expr.UInt64Kind:
return "uint64"
case expr.Float32Kind:
return "float32"
case expr.Float64Kind:
return "float64"
case expr.StringKind:
return "string"
case expr.BytesKind:
return "[]byte"
case expr.AnyKind:
return "interface{}"
default:
panic(fmt.Sprintf("cannot compute native Go type for %T", t)) // bug
}
}
// AttributeTags computes the struct field tags from its metadata if any.
func AttributeTags(parent, att *expr.AttributeExpr) string {
var elems []string
keys := make([]string, len(att.Meta))
i := 0
for k := range att.Meta {
keys[i] = k
i++
}
sort.Strings(keys)
for _, key := range keys {
val := att.Meta[key]
if strings.HasPrefix(key, "struct:tag:") {
name := key[11:]
value := strings.Join(val, ",")
elems = append(elems, fmt.Sprintf("%s:\"%s\"", name, value))
}
}
if len(elems) > 0 {
return " `" + strings.Join(elems, " ") + "`"
}
return ""
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/goa.git
git@gitee.com:mirrors/goa.git
mirrors
goa
goa
v2.2.3

搜索帮助