github.com/songzhibin97/gkit@v1.2.13/parser/parse_go/transform.go (about)

     1  package parse_go
     2  
     3  var GoToPBMapping = map[string]string{
     4  	"int":     "int64",
     5  	"float":   "double",
     6  	"int16":   "int32",
     7  	"float16": "double",
     8  	"float64": "double",
     9  	"float32": "float",
    10  	"int32":   "int32",
    11  	"int64":   "int64",
    12  	"uint32":  "uint32",
    13  	"uint64":  "uint64",
    14  	"bool":    "bool",
    15  	"string":  "string",
    16  	"[]byte":  "bytes",
    17  }
    18  
    19  // GoTypeToPB go type 转化成 pb type
    20  func GoTypeToPB(s string) string {
    21  	if v, ok := GoToPBMapping[s]; ok {
    22  		return v
    23  	}
    24  	return s
    25  }
    26  
    27  // IsMappingKey 判断是否是 pb map的key类型
    28  func IsMappingKey(key string) bool {
    29  	// Map key cannot be float, double, bytes, message, or enum types
    30  	switch key {
    31  	case "int32", "int64", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64", "string":
    32  		return true
    33  	default:
    34  		return false
    35  	}
    36  }
    37  
    38  func addOne(a int) int {
    39  	return a + 1
    40  }