MgoFieldToGoStruct convert to go struct
(name string, fs []*MgoField)
| 331 | |
| 332 | // MgoFieldToGoStruct convert to go struct |
| 333 | func 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 | |
| 354 | func toSingular(word string) string { |
| 355 | if strings.HasSuffix(word, "es") { |
no outgoing calls