本文整理汇总了Golang中kego/io/system.Type.PassedAsPointer方法的典型用法代码示例。如果您正苦于以下问题:Golang Type.PassedAsPointer方法的具体用法?Golang Type.PassedAsPointer怎么用?Golang Type.PassedAsPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kego/io/system.Type
的用法示例。
在下文中一共展示了Type.PassedAsPointer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: printRepacker
func printRepacker(ctx context.Context, env *envctx.Env, g *builder.Builder, typ *system.Type) error {
name := system.GoName(typ.Id.Name)
context_Context := g.SprintRef("context", "Context")
system_JsonType := g.SprintRef("kego.io/system", "JsonType")
ptr := typ.PassedAsPointerString(ctx)
v := "v"
if typ.PassedAsPointer(ctx) {
v = "(*v)"
}
g.Println("func (v ", ptr, name, ") Repack(ctx ", context_Context, ") (data interface{}, typePackage string, typeName string, jsonType ", system_JsonType, ", err error) {")
{
g.Println("if v == nil {")
{
system_J_NULL := g.SprintRef("kego.io/system", "J_NULL")
g.Println("return nil, ", strconv.Quote(typ.Id.Package), ", ", strconv.Quote(typ.Id.Name), ", ", system_J_NULL, ", nil")
}
g.Println("}")
jtype := typ.NativeJsonType(ctx)
var jsonType string
switch jtype {
case system.J_NUMBER:
jsonType = g.SprintRef("kego.io/system", "J_NUMBER")
case system.J_STRING:
jsonType = g.SprintRef("kego.io/system", "J_STRING")
case system.J_BOOL:
jsonType = g.SprintRef("kego.io/system", "J_BOOL")
case system.J_MAP:
jsonType = g.SprintRef("kego.io/system", "J_MAP")
case system.J_OBJECT:
jsonType = g.SprintRef("kego.io/system", "J_OBJECT")
case system.J_ARRAY:
jsonType = g.SprintRef("kego.io/system", "J_ARRAY")
case system.J_NULL:
jsonType = g.SprintRef("kego.io/system", "J_NULL")
}
kind, _ := typ.Kind(ctx)
switch kind {
case system.KindStruct:
g.Println("m := map[string]interface{}{}")
structType := typ
if typ.Alias != nil {
structType = system.WrapRule(ctx, typ.Alias).Parent
}
for _, embedRef := range structType.AllEmbeds() {
embedName := system.GoName(embedRef.Name)
g.Println("if v.", embedName, " != nil {")
{
g.Println("ob, _, _, _, err := v.", embedName, ".Repack(ctx)")
g.Println("if err != nil {")
{
g.Println(`return nil, "", "", "", err`)
}
g.Println("}")
g.Println("for key, val := range ob.(map[string]interface{}) {")
{
g.Println("m[key] = val")
}
g.Println("}")
}
g.Println("}")
}
for _, f := range structType.SortedFields() {
fieldRule := system.WrapRule(ctx, f.Rule)
fieldName := system.GoName(f.Name)
fieldType := fieldRule.Parent
kind, alias := fieldRule.Kind(ctx)
switch {
case kind == system.KindStruct || alias:
g.Println("if v.", fieldName, " != nil {")
{
if err := printRepackCode(ctx, env, g, "v."+fieldName, "ob0", 0, f.Rule, true); err != nil {
return kerr.Wrap("WSARHJIFHS", err)
}
g.Println("m[", strconv.Quote(f.Name), "] = ", "ob0")
}
g.Println("}")
case kind == system.KindValue:
switch fieldType.NativeJsonType(ctx) {
case system.J_STRING:
g.Println("if v.", fieldName, " != \"\" {")
case system.J_NUMBER:
g.Println("if v.", fieldName, " != 0.0 {")
case system.J_BOOL:
g.Println("if v.", fieldName, " != false {")
}
{
if err := printRepackCode(ctx, env, g, "v."+fieldName, "ob0", 0, f.Rule, true); err != nil {
return kerr.Wrap("YYDYVIMXPM", err)
}
g.Println("m[", strconv.Quote(f.Name), "] = ", "ob0")
}
g.Println("}")
case kind == system.KindArray ||
kind == system.KindMap ||
kind == system.KindInterface:
g.Println("if v.", fieldName, " != nil {")
{
if err := printRepackCode(ctx, env, g, "v."+fieldName, "ob0", 0, f.Rule, true); err != nil {
//.........这里部分代码省略.........