MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / MgoFieldToGoStruct

Function MgoFieldToGoStruct

pkg/sql2code/parser/mongodb.go:333–352  ·  view source on GitHub ↗

MgoFieldToGoStruct convert to go struct

(name string, fs []*MgoField)

Source from the content-addressed store, hash-verified

331
332// MgoFieldToGoStruct convert to go struct
333func MgoFieldToGoStruct(name string, fs []*MgoField) string {
334 var str = ""
335 var objStr string
336
337 for _, f := range fs {
338 if f.Name == oidName {
339 str += " ID primitive.ObjectID `bson:\"_id\" json:\"id\"`\n"
340 continue
341 }
342 if f.Type == goTypeInterface || f.Type == goTypeSliceInterface {
343 f.Type = xstrings.ToCamelCase(f.Name)
344 }
345 str += fmt.Sprintf(" %s %s `bson:\"%s\" json:\"%s\"`\n", xstrings.ToCamelCase(f.Name), f.Type, f.Name, f.Name)
346 if f.ObjectStr != "" {
347 objStr += f.ObjectStr + "\n"
348 }
349 }
350
351 return fmt.Sprintf("type %s struct {\n%s}\n\n%s\n", xstrings.ToCamelCase(name), str, objStr)
352}
353
354func toSingular(word string) string {
355 if strings.HasSuffix(word, "es") {

Callers 1

Calls

no outgoing calls

Tested by 1