From 7172d5b49dce2cde6b607a0fc5333794fb43e121 Mon Sep 17 00:00:00 2001 From: Pat Moroney Date: Tue, 19 Sep 2017 14:53:57 -0600 Subject: [PATCH] Add httpBody helper function --- helpers/helpers.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/helpers/helpers.go b/helpers/helpers.go index 1721c3b..72d8aeb 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -99,6 +99,7 @@ var ProtoHelpersFuncMap = template.FuncMap{ "namespacedFlowType": namespacedFlowType, "httpVerb": httpVerb, "httpPath": httpPath, + "httpBody": httpBody, "shortType": shortType, "urlHasVarsFromMessage": urlHasVarsFromMessage, } @@ -427,6 +428,19 @@ func httpVerb(m *descriptor.MethodDescriptorProto) string { } } +func httpBody(m *descriptor.MethodDescriptorProto) string { + + ext, err := proto.GetExtension(m.Options, options.E_Http) + if err != nil { + return err.Error() + } + opts, ok := ext.(*options.HttpRule) + if !ok { + return fmt.Sprintf("extension is %T; want an HttpRule", ext) + } + return opts.Body +} + func urlHasVarsFromMessage(path string, d *ggdescriptor.Message) bool { for _, field := range d.Field { if !isFieldMessage(field) {