github.com/cloudwego/kitex@v0.9.0/tool/internal_pkg/tpl/handler.method.go (about) 1 // Copyright 2022 CloudWeGo Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tpl 16 17 // HandlerMethodsTpl is the template for generating methods in handler.go. 18 var HandlerMethodsTpl string = `{{define "HandlerMethod"}} 19 {{range .AllMethods}} 20 {{- if or .ClientStreaming .ServerStreaming}} 21 func (s *{{$.ServiceName}}Impl) {{.Name}}({{if not .ClientStreaming}}{{range .Args}}{{LowerFirst .Name}} {{.Type}}, {{end}}{{end}}stream {{.PkgRefName}}.{{.ServiceName}}_{{.RawName}}Server) (err error) { 22 println("{{.Name}} called") 23 return 24 } 25 {{- else}} 26 {{- if .Void}} 27 // {{.Name}} implements the {{.ServiceName}}Impl interface. 28 {{- if .Oneway}} 29 // Oneway methods are not guaranteed to receive 100% of the requests sent by the client. 30 // And the client may not perceive the loss of requests due to network packet loss. 31 // If possible, do not use oneway methods. 32 {{- end}} 33 func (s *{{$.ServiceName}}Impl) {{.Name}}(ctx context.Context {{- range .Args}}, {{LowerFirst .Name}} {{.Type}}{{end}}) (err error) { 34 // TODO: Your code here... 35 return 36 } 37 {{else -}} 38 // {{.Name}} implements the {{.ServiceName}}Impl interface. 39 func (s *{{$.ServiceName}}Impl) {{.Name}}(ctx context.Context {{range .Args}}, {{LowerFirst .Name}} {{.Type}}{{end}} ) (resp {{.Resp.Type}}, err error) { 40 // TODO: Your code here... 41 return 42 } 43 {{end}} 44 {{end}} 45 {{end}} 46 {{end}}{{/* define "HandlerMethod" */}} 47 `