tmpl.go
1.3 KB
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
package tmpl
//param -c Auth -m Login
//Controller Auth
//ControllerLowcase auth
//Method Login
//MethodLowcase login
var ControllerMethod =`
//{{.Method}}
func(this *{{.Controller}}Controller){{.Method}}(){
var msg *mybeego.Message
defer func(){
this.Resp(msg)
}()
var request *protocol.{{.Method}}Request
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
log.Error(err)
msg = mybeego.NewMessage(1)
return
}
if b,m :=this.Valid(request);!b{
msg = m
return
}
msg = protocol.NewReturnResponse({{.ControllerLowcase}}.{{.Method}}(request))
}
`
var ProtocolModel =`
/*{{.Method}} */
type {{.Method}}Request struct {
Xxx string` +"`json:\"xxx\" valid:\"Required\"`" +`
}
type {{.Method}}Response struct {
}
`
//Method Login
var Handler =`
func {{.Method}}(request *protocol.{{.Method}}Request)(rsp *protocol.{{.Method}}Response,err error){
var (
)
rsp =&protocol.{{.Method}}Response{}
return
}
`
var Router =`
/*{{.MethodLowcase}} controller*/
{
{{.ControllerLowcase}} :=&v1.{{.Controller}}Controller{}
nsV1.Router("/{{.ControllerLowcase}}/{{.MethodLowcase}}",{{.ControllerLowcase}},"post:{{.Method}}")
}
`
//Name Phone
//NameLowcase phone
//TypeName string
//ValidString Required;Mobile
var Param =`
{{.Name}} {{.TypeName}} `+"`json:\"{{.NameLowcase}}\" valid:\"{{.ValidString}}\"`"