1 // Copyright (c) 2017 Cisco and/or its affiliates.
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:
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
28 // generatedCodeVersion indicates a version of the generated code.
29 // It is incremented whenever an incompatibility between the generated code and
30 // GoVPP api package is introduced; the generated code references
31 // a constant, api.GoVppAPIPackageIsVersionN (where N is generatedCodeVersion).
32 const generatedCodeVersion = 1
35 inputFileExt = ".api.json" // file extension of the VPP API files
36 outputFileExt = ".ba.go" // file extension of the Go generated files
38 govppApiImportPath = "git.fd.io/govpp.git/api" // import path of the govpp API package
40 constModuleName = "ModuleName" // module name constant
41 constAPIVersion = "APIVersion" // API version constant
42 constVersionCrc = "VersionCrc" // version CRC constant
44 unionDataField = "XXX_UnionData" // name for the union data field
46 serviceApiName = "RPCService" // name for the RPC service interface
47 serviceImplName = "serviceClient" // name for the RPC service implementation
48 serviceClientName = "ServiceClient" // name for the RPC service client
51 // context is a structure storing data for code generation
53 inputFile string // input file with VPP API in JSON
54 outputFile string // output file with generated Go package
56 inputData []byte // contents of the input file
58 includeAPIVersion bool // include constant with API version string
59 includeComments bool // include parts of original source in comments
60 includeBinapiNames bool // include binary API names as struct tag
61 includeServices bool // include service interface with client implementation
63 moduleName string // name of the source VPP module
64 packageName string // name of the Go package being generated
66 packageData *Package // parsed package data
69 // newContext returns context details of the code generation task
70 func newContext(inputFile, outputDir string) (*context, error) {
71 if !strings.HasSuffix(inputFile, inputFileExt) {
72 return nil, fmt.Errorf("invalid input file name: %q", inputFile)
80 inputFileName := filepath.Base(inputFile)
81 ctx.moduleName = inputFileName[:strings.Index(inputFileName, ".")]
83 // alter package names for modules that are reserved keywords in Go
84 switch ctx.moduleName {
86 ctx.packageName = "interfaces"
88 ctx.packageName = "maps"
90 ctx.packageName = ctx.moduleName
94 packageDir := filepath.Join(outputDir, ctx.packageName)
95 outputFileName := ctx.packageName + outputFileExt
96 ctx.outputFile = filepath.Join(packageDir, outputFileName)
101 func generatePackage(ctx *context, w io.Writer) error {
102 logf("generating package %q", ctx.packageName)
104 fmt.Fprintln(w, "// Code generated by GoVPP's binapi-generator. DO NOT EDIT.")
105 fmt.Fprintf(w, "// source: %s\n", ctx.inputFile)
108 generateHeader(ctx, w)
110 // generate module desc
111 fmt.Fprintln(w, "const (")
112 fmt.Fprintf(w, "\t// %s is the name of this module.\n", constModuleName)
113 fmt.Fprintf(w, "\t%s = \"%s\"\n", constModuleName, ctx.moduleName)
115 if ctx.includeAPIVersion {
116 if ctx.packageData.Version != "" {
117 fmt.Fprintf(w, "\t// %s is the API version of this module.\n", constAPIVersion)
118 fmt.Fprintf(w, "\t%s = \"%s\"\n", constAPIVersion, ctx.packageData.Version)
120 fmt.Fprintf(w, "\t// %s is the CRC of this module.\n", constVersionCrc)
121 fmt.Fprintf(w, "\t%s = %v\n", constVersionCrc, ctx.packageData.CRC)
127 if len(ctx.packageData.Enums) > 0 {
128 for _, enum := range ctx.packageData.Enums {
129 if imp, ok := ctx.packageData.Imports[enum.Name]; ok {
130 generateImportedAlias(ctx, w, enum.Name, &imp)
133 generateEnum(ctx, w, &enum)
138 if len(ctx.packageData.Aliases) > 0 {
139 for _, alias := range ctx.packageData.Aliases {
140 if imp, ok := ctx.packageData.Imports[alias.Name]; ok {
141 generateImportedAlias(ctx, w, alias.Name, &imp)
144 generateAlias(ctx, w, &alias)
149 if len(ctx.packageData.Types) > 0 {
150 for _, typ := range ctx.packageData.Types {
151 if imp, ok := ctx.packageData.Imports[typ.Name]; ok {
152 generateImportedAlias(ctx, w, typ.Name, &imp)
155 generateType(ctx, w, &typ)
160 if len(ctx.packageData.Unions) > 0 {
161 for _, union := range ctx.packageData.Unions {
162 if imp, ok := ctx.packageData.Imports[union.Name]; ok {
163 generateImportedAlias(ctx, w, union.Name, &imp)
166 generateUnion(ctx, w, &union)
171 if len(ctx.packageData.Messages) > 0 {
172 for _, msg := range ctx.packageData.Messages {
173 generateMessage(ctx, w, &msg)
176 // generate message registrations
177 fmt.Fprintln(w, "func init() {")
178 for _, msg := range ctx.packageData.Messages {
179 name := camelCaseName(msg.Name)
180 fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n", name, ctx.moduleName+"."+name)
185 // generate list of messages
186 fmt.Fprintf(w, "// Messages returns list of all messages in this module.\n")
187 fmt.Fprintln(w, "func AllMessages() []api.Message {")
188 fmt.Fprintln(w, "\treturn []api.Message{")
189 for _, msg := range ctx.packageData.Messages {
190 name := camelCaseName(msg.Name)
191 fmt.Fprintf(w, "\t(*%s)(nil),\n", name)
197 if ctx.includeServices {
199 if len(ctx.packageData.Services) > 0 {
200 generateServices(ctx, w, ctx.packageData.Services)
204 generateFooter(ctx, w)
209 func generateHeader(ctx *context, w io.Writer) {
210 fmt.Fprintln(w, "/*")
211 fmt.Fprintf(w, "Package %s is a generated VPP binary API for '%s' module.\n", ctx.packageName, ctx.moduleName)
213 fmt.Fprintln(w, "It consists of:")
214 printObjNum := func(obj string, num int) {
217 if strings.HasSuffix(obj, "s") {
224 fmt.Fprintf(w, "\t%3d %s\n", num, obj)
227 printObjNum("enum", len(ctx.packageData.Enums))
228 printObjNum("alias", len(ctx.packageData.Aliases))
229 printObjNum("type", len(ctx.packageData.Types))
230 printObjNum("union", len(ctx.packageData.Unions))
231 printObjNum("message", len(ctx.packageData.Messages))
232 printObjNum("service", len(ctx.packageData.Services))
233 fmt.Fprintln(w, "*/")
234 fmt.Fprintf(w, "package %s\n", ctx.packageName)
237 fmt.Fprintln(w, "import (")
238 fmt.Fprintf(w, "\tapi \"%s\"\n", govppApiImportPath)
239 fmt.Fprintf(w, "\tbytes \"%s\"\n", "bytes")
240 fmt.Fprintf(w, "\tcontext \"%s\"\n", "context")
241 fmt.Fprintf(w, "\tio \"%s\"\n", "io")
242 fmt.Fprintf(w, "\tstrconv \"%s\"\n", "strconv")
243 fmt.Fprintf(w, "\tstruc \"%s\"\n", "github.com/lunixbochs/struc")
244 if len(ctx.packageData.Imports) > 0 {
246 for _, imp := range getImports(ctx) {
247 impPkg := getImportPkg(filepath.Dir(ctx.outputFile), imp)
248 fmt.Fprintf(w, "\t%s \"%s\"\n", imp, strings.TrimSpace(impPkg))
255 func getImportPkg(outputDir string, pkg string) string {
256 absPath, _ := filepath.Abs(filepath.Join(outputDir, "..", pkg))
257 cmd := exec.Command("go", "list", absPath)
258 var errbuf, outbuf bytes.Buffer
261 if err := cmd.Run(); err != nil {
262 fmt.Printf("ERR: %v\n", errbuf.String())
265 return outbuf.String()
268 func getImports(ctx *context) (imports []string) {
269 impmap := map[string]struct{}{}
270 for _, imp := range ctx.packageData.Imports {
271 if _, ok := impmap[imp.Package]; !ok {
272 imports = append(imports, imp.Package)
273 impmap[imp.Package] = struct{}{}
276 sort.Strings(imports)
280 func generateFooter(ctx *context, w io.Writer) {
281 fmt.Fprintln(w, "// This is a compile-time assertion to ensure that this generated file")
282 fmt.Fprintln(w, "// is compatible with the GoVPP api package it is being compiled against.")
283 fmt.Fprintln(w, "// A compilation error at this line likely means your copy of the")
284 fmt.Fprintln(w, "// GoVPP api package needs to be updated.")
285 fmt.Fprintf(w, "const _ = api.GoVppAPIPackageIsVersion%d // please upgrade the GoVPP api package\n", generatedCodeVersion)
288 fmt.Fprintf(w, "// Reference imports to suppress errors if they are not otherwise used.\n")
289 fmt.Fprintf(w, "var _ = api.RegisterMessage\n")
290 fmt.Fprintf(w, "var _ = bytes.NewBuffer\n")
291 fmt.Fprintf(w, "var _ = context.Background\n")
292 fmt.Fprintf(w, "var _ = io.Copy\n")
293 fmt.Fprintf(w, "var _ = strconv.Itoa\n")
294 fmt.Fprintf(w, "var _ = struc.Pack\n")
297 func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) {
298 if objKind == "service" {
299 fmt.Fprintf(w, "// %s represents RPC service API for %s module.\n", goName, ctx.moduleName)
301 fmt.Fprintf(w, "// %s represents VPP binary API %s '%s'.\n", goName, objKind, vppName)
304 if !ctx.includeComments {
308 var isNotSpace = func(r rune) bool {
309 return !unicode.IsSpace(r)
312 // print out the source of the generated object
315 objTitle := fmt.Sprintf(`"%s",`, vppName)
317 case "alias", "service":
318 objTitle = fmt.Sprintf(`"%s": {`, vppName)
322 inputBuff := bytes.NewBuffer(ctx.inputData)
325 var trimIndent string
328 line, err := inputBuff.ReadString('\n')
334 noSpaceAt := strings.IndexFunc(line, isNotSpace)
336 indent = strings.Index(line, objTitle)
340 trimIndent = line[:indent]
341 // If no other non-whitespace character then we are at the message header.
342 if trimmed := strings.TrimSpace(line); trimmed == objTitle {
344 fmt.Fprintln(w, "//")
346 } else if noSpaceAt < indent {
347 break // end of the definition in JSON for array types
348 } else if objFound && mapType && noSpaceAt <= indent {
349 fmt.Fprintf(w, "//\t%s", strings.TrimPrefix(line, trimIndent))
350 break // end of the definition in JSON for map types (aliases, services)
352 fmt.Fprintf(w, "//\t%s", strings.TrimPrefix(line, trimIndent))
355 fmt.Fprintln(w, "//")
358 func generateEnum(ctx *context, w io.Writer, enum *Enum) {
359 name := camelCaseName(enum.Name)
360 typ := binapiTypes[enum.Type]
362 logf(" writing enum %q (%s) with %d entries", enum.Name, name, len(enum.Entries))
364 // generate enum comment
365 generateComment(ctx, w, name, enum.Name, "enum")
367 // generate enum definition
368 fmt.Fprintf(w, "type %s %s\n", name, typ)
371 // generate enum entries
372 fmt.Fprintln(w, "const (")
373 for _, entry := range enum.Entries {
374 fmt.Fprintf(w, "\t%s %s = %v\n", entry.Name, name, entry.Value)
379 // generate enum conversion maps
380 fmt.Fprintf(w, "var %s_name = map[%s]string{\n", name, typ)
381 for _, entry := range enum.Entries {
382 fmt.Fprintf(w, "\t%v: \"%s\",\n", entry.Value, entry.Name)
387 fmt.Fprintf(w, "var %s_value = map[string]%s{\n", name, typ)
388 for _, entry := range enum.Entries {
389 fmt.Fprintf(w, "\t\"%s\": %v,\n", entry.Name, entry.Value)
394 fmt.Fprintf(w, "func (x %s) String() string {\n", name)
395 fmt.Fprintf(w, "\ts, ok := %s_name[%s(x)]\n", name, typ)
396 fmt.Fprintf(w, "\tif ok { return s }\n")
397 fmt.Fprintf(w, "\treturn strconv.Itoa(int(x))\n")
402 func generateImportedAlias(ctx *context, w io.Writer, tName string, imp *Import) {
403 name := camelCaseName(tName)
405 fmt.Fprintf(w, "type %s = %s.%s\n", name, imp.Package, name)
410 func generateAlias(ctx *context, w io.Writer, alias *Alias) {
411 name := camelCaseName(alias.Name)
413 logf(" writing type %q (%s), length: %d", alias.Name, name, alias.Length)
415 // generate struct comment
416 generateComment(ctx, w, name, alias.Name, "alias")
418 // generate struct definition
419 fmt.Fprintf(w, "type %s ", name)
421 if alias.Length > 0 {
422 fmt.Fprintf(w, "[%d]", alias.Length)
425 dataType := convertToGoType(ctx, alias.Type)
426 fmt.Fprintf(w, "%s\n", dataType)
431 func generateUnion(ctx *context, w io.Writer, union *Union) {
432 name := camelCaseName(union.Name)
434 logf(" writing union %q (%s) with %d fields", union.Name, name, len(union.Fields))
436 // generate struct comment
437 generateComment(ctx, w, name, union.Name, "union")
439 // generate struct definition
440 fmt.Fprintln(w, "type", name, "struct {")
442 // maximum size for union
443 maxSize := getUnionSize(ctx, union)
445 // generate data field
446 fmt.Fprintf(w, "\t%s [%d]byte\n", unionDataField, maxSize)
448 // generate end of the struct
451 // generate name getter
452 generateTypeNameGetter(w, name, union.Name)
454 // generate CRC getter
456 generateCrcGetter(w, name, union.CRC)
459 // generate getters for fields
460 for _, field := range union.Fields {
461 fieldName := camelCaseName(field.Name)
462 fieldType := convertToGoType(ctx, field.Type)
463 generateUnionGetterSetter(w, name, fieldName, fieldType)
466 // generate union methods
467 //generateUnionMethods(w, name)
472 // generateUnionMethods generates methods that implement struc.Custom
473 // interface to allow having XXX_uniondata field unexported
474 // TODO: do more testing when unions are actually used in some messages
475 /*func generateUnionMethods(w io.Writer, structName string) {
476 // generate struc.Custom implementation for union
478 func (u *%[1]s) Pack(p []byte, opt *struc.Options) (int, error) {
479 var b = new(bytes.Buffer)
480 if err := struc.PackWithOptions(b, u.union_data, opt); err != nil {
486 func (u *%[1]s) Unpack(r io.Reader, length int, opt *struc.Options) error {
487 return struc.UnpackWithOptions(r, u.union_data[:], opt)
489 func (u *%[1]s) Size(opt *struc.Options) int {
490 return len(u.union_data)
492 func (u *%[1]s) String() string {
493 return string(u.union_data[:])
498 func generateUnionGetterSetter(w io.Writer, structName string, getterField, getterStruct string) {
500 func %[1]s%[2]s(a %[3]s) (u %[1]s) {
504 func (u *%[1]s) Set%[2]s(a %[3]s) {
505 var b = new(bytes.Buffer)
506 if err := struc.Pack(b, &a); err != nil {
509 copy(u.%[4]s[:], b.Bytes())
511 func (u *%[1]s) Get%[2]s() (a %[3]s) {
512 var b = bytes.NewReader(u.%[4]s[:])
516 `, structName, getterField, getterStruct, unionDataField)
519 func generateType(ctx *context, w io.Writer, typ *Type) {
520 name := camelCaseName(typ.Name)
522 logf(" writing type %q (%s) with %d fields", typ.Name, name, len(typ.Fields))
524 // generate struct comment
525 generateComment(ctx, w, name, typ.Name, "type")
527 // generate struct definition
528 fmt.Fprintf(w, "type %s struct {\n", name)
530 // generate struct fields
531 for i, field := range typ.Fields {
532 // skip internal fields
533 switch strings.ToLower(field.Name) {
534 case crcField, msgIdField:
538 generateField(ctx, w, typ.Fields, i)
541 // generate end of the struct
544 // generate name getter
545 generateTypeNameGetter(w, name, typ.Name)
547 // generate CRC getter
549 generateCrcGetter(w, name, typ.CRC)
555 func generateMessage(ctx *context, w io.Writer, msg *Message) {
556 name := camelCaseName(msg.Name)
558 logf(" writing message %q (%s) with %d fields", msg.Name, name, len(msg.Fields))
560 // generate struct comment
561 generateComment(ctx, w, name, msg.Name, "message")
563 // generate struct definition
564 fmt.Fprintf(w, "type %s struct {", name)
566 msgType := otherMessage
567 wasClientIndex := false
569 // generate struct fields
571 for i, field := range msg.Fields {
573 if field.Name == clientIndexField {
574 // "client_index" as the second member,
575 // this might be an event message or a request
576 msgType = eventMessage
577 wasClientIndex = true
578 } else if field.Name == contextField {
579 // reply needs "context" as the second member
580 msgType = replyMessage
583 if wasClientIndex && field.Name == contextField {
584 // request needs "client_index" as the second member
585 // and "context" as the third member
586 msgType = requestMessage
590 // skip internal fields
591 switch strings.ToLower(field.Name) {
592 case crcField, msgIdField:
594 case clientIndexField, contextField:
604 generateField(ctx, w, msg.Fields, i)
607 // generate end of the struct
610 // generate message methods
611 generateMessageResetMethod(w, name)
612 generateMessageNameGetter(w, name, msg.Name)
613 generateCrcGetter(w, name, msg.CRC)
614 generateMessageTypeGetter(w, name, msgType)
619 func generateField(ctx *context, w io.Writer, fields []Field, i int) {
622 fieldName := strings.TrimPrefix(field.Name, "_")
623 fieldName = camelCaseName(fieldName)
625 dataType := convertToGoType(ctx, field.Type)
626 fieldType := dataType
628 // generate length field for strings
629 if field.Type == "string" && field.Length == 0 {
630 fmt.Fprintf(w, "\tXXX_%sLen uint32 `struc:\"sizeof=%s\"`\n", fieldName, fieldName)
633 // check if it is array
634 if field.Length > 0 || field.SizeFrom != "" {
635 if dataType == "uint8" {
638 if dataType == "string" && field.SpecifiedLen {
642 fieldType = "[]" + dataType
645 fmt.Fprintf(w, "\t%s %s", fieldName, fieldType)
647 fieldTags := map[string]string{}
649 if field.Length > 0 && field.SpecifiedLen {
651 fieldTags["struc"] = fmt.Sprintf("[%d]%s", field.Length, dataType)
653 for _, f := range fields {
654 if f.SizeFrom == field.Name {
655 // variable sized array
656 sizeOfName := camelCaseName(f.Name)
657 fieldTags["struc"] = fmt.Sprintf("sizeof=%s", sizeOfName)
662 if ctx.includeBinapiNames {
663 fieldTags["binapi"] = field.Name
665 if field.Meta.Limit > 0 {
666 fieldTags["binapi"] = fmt.Sprintf("%s,limit=%d", fieldTags["binapi"], field.Meta.Limit)
669 if len(fieldTags) > 0 {
670 fmt.Fprintf(w, "\t`")
672 for k := range fieldTags {
673 keys = append(keys, k)
677 for _, tt := range keys {
678 t, ok := fieldTags[tt]
686 fmt.Fprintf(w, `%s:"%s"`, tt, t)
694 func generateMessageResetMethod(w io.Writer, structName string) {
695 fmt.Fprintf(w, "func (m *%[1]s) Reset() { *m = %[1]s{} }\n", structName)
698 func generateMessageNameGetter(w io.Writer, structName, msgName string) {
699 fmt.Fprintf(w, "func (*%s) GetMessageName() string { return %q }\n", structName, msgName)
702 func generateTypeNameGetter(w io.Writer, structName, msgName string) {
703 fmt.Fprintf(w, "func (*%s) GetTypeName() string { return %q }\n", structName, msgName)
706 func generateCrcGetter(w io.Writer, structName, crc string) {
707 crc = strings.TrimPrefix(crc, "0x")
708 fmt.Fprintf(w, "func (*%s) GetCrcString() string { return %q }\n", structName, crc)
711 func generateMessageTypeGetter(w io.Writer, structName string, msgType MessageType) {
712 fmt.Fprintf(w, "func (*"+structName+") GetMessageType() api.MessageType {")
713 if msgType == requestMessage {
714 fmt.Fprintf(w, "\treturn api.RequestMessage")
715 } else if msgType == replyMessage {
716 fmt.Fprintf(w, "\treturn api.ReplyMessage")
717 } else if msgType == eventMessage {
718 fmt.Fprintf(w, "\treturn api.EventMessage")
720 fmt.Fprintf(w, "\treturn api.OtherMessage")
726 func generateServices(ctx *context, w io.Writer, services []Service) {
728 // generate services comment
729 generateComment(ctx, w, serviceApiName, "services", "service")
731 // generate service api
732 fmt.Fprintf(w, "type %s interface {\n", serviceApiName)
733 for _, svc := range services {
734 generateServiceMethod(ctx, w, &svc)
740 // generate client implementation
741 fmt.Fprintf(w, "type %s struct {\n", serviceImplName)
742 fmt.Fprintf(w, "\tch api.Channel\n")
746 // generate client constructor
747 fmt.Fprintf(w, "func New%s(ch api.Channel) %s {\n", serviceClientName, serviceApiName)
748 fmt.Fprintf(w, "\treturn &%s{ch}\n", serviceImplName)
752 for _, svc := range services {
753 method := camelCaseName(svc.RequestType)
754 if m := strings.TrimSuffix(method, "Dump"); method != m {
758 fmt.Fprintf(w, "func (c *%s) ", serviceImplName)
759 generateServiceMethod(ctx, w, &svc)
760 fmt.Fprintln(w, " {")
762 streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
763 fmt.Fprintf(w, "\tstream := c.ch.SendMultiRequest(in)\n")
764 fmt.Fprintf(w, "\tx := &%s{stream}\n", streamImpl)
765 fmt.Fprintf(w, "\treturn x, nil\n")
766 } else if replyTyp := camelCaseName(svc.ReplyType); replyTyp != "" {
767 fmt.Fprintf(w, "\tout := new(%s)\n", replyTyp)
768 fmt.Fprintf(w, "\terr:= c.ch.SendRequest(in).ReceiveReply(out)\n")
769 fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
770 fmt.Fprintf(w, "\treturn out, nil\n")
772 fmt.Fprintf(w, "\tc.ch.SendRequest(in)\n")
773 fmt.Fprintf(w, "\treturn nil\n")
779 replyTyp := camelCaseName(svc.ReplyType)
780 method := camelCaseName(svc.RequestType)
781 if m := strings.TrimSuffix(method, "Dump"); method != m {
784 streamApi := fmt.Sprintf("%s_%sClient", serviceApiName, method)
786 fmt.Fprintf(w, "type %s interface {\n", streamApi)
787 fmt.Fprintf(w, "\tRecv() (*%s, error)\n", replyTyp)
791 streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, method)
792 fmt.Fprintf(w, "type %s struct {\n", streamImpl)
793 fmt.Fprintf(w, "\tapi.MultiRequestCtx\n")
797 fmt.Fprintf(w, "func (c *%s) Recv() (*%s, error) {\n", streamImpl, replyTyp)
798 fmt.Fprintf(w, "\tm := new(%s)\n", replyTyp)
799 fmt.Fprintf(w, "\tstop, err := c.MultiRequestCtx.ReceiveReply(m)\n")
800 fmt.Fprintf(w, "\tif err != nil { return nil, err }\n")
801 fmt.Fprintf(w, "\tif stop { return nil, io.EOF }\n")
802 fmt.Fprintf(w, "\treturn m, nil\n")
811 func generateServiceMethod(ctx *context, w io.Writer, svc *Service) {
812 reqTyp := camelCaseName(svc.RequestType)
814 // method name is same as parameter type name by default
817 // use Dump as prefix instead of suffix for stream services
818 if m := strings.TrimSuffix(method, "Dump"); method != m {
823 params := fmt.Sprintf("in *%s", reqTyp)
826 if replyType := camelCaseName(svc.ReplyType); replyType != "" {
829 replyTyp = fmt.Sprintf("%s_%sClient", serviceApiName, method)
831 replyTyp = fmt.Sprintf("*%s", replyType)
833 returns = fmt.Sprintf("(%s, error)", replyTyp)
836 fmt.Fprintf(w, "\t%s(ctx context.Context, %s) %s", method, params, returns)