Skip to content

Commit

Permalink
Shallow copy of URL instead of reparsing it
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Pasquier <[email protected]>
  • Loading branch information
simonpasquier committed Jul 17, 2018
1 parent b76b607 commit d9d0552
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,7 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...)
tmplText = tmplText(n.tmpl, data, &err)
tmplHTML = tmplHTML(n.tmpl, data, &err)
// n.conf.APIURL is already checked at configuration load time.
url, _ = url.Parse(n.conf.APIURL.String())
url = *n.conf.APIURL
)
url.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", n.conf.RoomID, n.conf.AuthToken)

Expand Down Expand Up @@ -885,8 +884,7 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
return false, fmt.Errorf("templating error: %s", err)
}

// n.conf.APIURL is already checked at configuration load time.
u, _ := url.Parse(n.conf.APIURL.String())
u := *n.conf.APIURL
u.Path += "gettoken"
u.RawQuery = parameters.Encode()

Expand Down Expand Up @@ -937,8 +935,7 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
return false, err
}

// n.conf.APIURL is already checked at configuration load time.
postMessageURL, _ := url.Parse(n.conf.APIURL.String())
postMessageURL := *n.conf.APIURL
postMessageURL.Path += "message/send?access_token=" + n.accessToken

req, err := http.NewRequest(http.MethodPost, postMessageURL.String(), &buf)
Expand Down Expand Up @@ -1059,11 +1056,10 @@ func (n *OpsGenie) createRequest(ctx context.Context, as ...*types.Alert) (*http
}

var (
msg interface{}
// n.conf.APIURL is already checked at configuration load time.
apiURL, _ = url.Parse(n.conf.APIURL.String())
alias = hashKey(key)
alerts = types.Alerts(as...)
msg interface{}
apiURL = *n.conf.APIURL
alias = hashKey(key)
alerts = types.Alerts(as...)
)
switch alerts.Status() {
case model.AlertResolved:
Expand Down Expand Up @@ -1169,11 +1165,10 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error

var err error
var (
alerts = types.Alerts(as...)
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...)
tmpl = tmplText(n.tmpl, data, &err)
// n.conf.APIURL is already checked at configuration load time.
apiURL, _ = url.Parse(n.conf.APIURL.String())
alerts = types.Alerts(as...)
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...)
tmpl = tmplText(n.tmpl, data, &err)
apiURL = *n.conf.APIURL
messageType = tmpl(n.conf.MessageType)
stateMessage = tmpl(n.conf.StateMessage)
)
Expand Down

0 comments on commit d9d0552

Please sign in to comment.