-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for HTTP POST
body content
#123
Conversation
Signed-off-by: rustyclock <rustyclock@protonmail.com>
Signed-off-by: rustyclock <rustyclock@protonmail.com>
exporter/util.go
Outdated
br := strings.NewReader(c.Body.Content) | ||
if c.Body.Templatize { | ||
tpl, err := template.New("base").Funcs(sprig.GenericFuncMap()).Parse(c.Body.Content) | ||
if err != nil { | ||
|
||
level.Error(logger).Log("msg", "Failed to create a new template from body content", "err", err, "content", c.Body.Content) //nolint:errcheck | ||
} | ||
var b strings.Builder | ||
if err := tpl.Execute(&b, tplValues); err != nil { | ||
level.Error(logger).Log("msg", "Failed to render template with values", "err", err, "tempalte", c.Body.Content) //nolint:errcheck | ||
|
||
// `tplValues` can contain sensitive values, so log it only when in debug mode | ||
level.Debug(logger).Log("msg", "Failed to render template with values", "err", err, "tempalte", c.Body.Content, "values", tplValues) //nolint:errcheck | ||
} | ||
br = strings.NewReader(b.String()) | ||
} | ||
req, err = http.NewRequest("POST", endpoint, br) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a little cleaner as a separate function, rather than all inline.
Something like this:
func renderBody(c ConfigBody, tplValues url.Values) (io.Reader, error) {...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactored it into a separate function now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit on the cod structure, otherwise looks good.
Signed-off-by: rustyclock <rustyclock@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* [FEATURE] Add support for HTTP POST body content #123 Signed-off-by: SuperQ <superq@gmail.com>
* [FEATURE] Add support for HTTP POST body content #123 Signed-off-by: SuperQ <superq@gmail.com>
closes #69