/
helpers.go
72 lines (67 loc) · 1.33 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package mysql_model
import (
"strings"
"github.com/krisnasw/go-grst/protoc-gen-cdd/descriptor"
)
func getGormTagAttribute(fieldext *descriptor.FieldDescriptorExt) string {
result := ""
if fieldext.MysqlField.PrimaryKey {
result = "primary_key"
}
if fieldext.MysqlField.ColumnName != "" {
if result != "" {
result += ";"
}
result += "column:" + fieldext.MysqlField.ColumnName
}
if fieldext.MysqlField.ColumnType != "" {
if result != "" {
result += ";"
}
result += "type:" + fieldext.MysqlField.ColumnType
}
return result
}
func getGoType(fieldext *descriptor.FieldDescriptorExt) string {
t := ""
if fieldext.GetTypeName() == "" {
t = strings.ToLower(strings.Replace(fieldext.GetType().String(), "TYPE_", "", -1))
if t == "double" {
t = "float64"
}
} else {
switch fieldext.GetTypeName() {
case ".google.protobuf.Timestamp":
t = "time.Time"
}
}
return t
}
func getGoStandartType(fieldext *descriptor.FieldDescriptorExt) string {
t := getGoType(fieldext)
switch t {
case "float32":
return "float64"
case "float64":
return t
case "int":
return t
case "int8":
return "int"
case "int16":
return "int"
case "int32":
return "int"
case "int64":
return "int"
case "uint":
return t
case "uint16":
return "uint"
case "uint32":
return "uint"
case "uint64":
return "uint"
}
return t
}