mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 19:00:54 -06:00
20faef8de5
* Convert Azure Application Insights datasource to Go Allows for alerting of Application Insights data source Closes: #15153 * Fix timeGrainReset * Default time interval for querys for alerts * Fix a few rename related bugs * Update readme to indicate App Insights alerting * Fix typo and add tests to ensure migration is happening * Address code review feedback (mostly typos and unintended changes)
53 lines
1016 B
Go
53 lines
1016 B
Go
package util
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// URLQueryReader is a ApiURL query type.
|
|
type URLQueryReader struct {
|
|
values url.Values
|
|
}
|
|
|
|
// NewURLQueryReader parses a raw query and returns it as a URLQueryReader type.
|
|
func NewURLQueryReader(urlInfo *url.URL) (*URLQueryReader, error) {
|
|
u, err := url.ParseQuery(urlInfo.RawQuery)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &URLQueryReader{
|
|
values: u,
|
|
}, nil
|
|
}
|
|
|
|
// Get parse parameters from an ApiURL. If the parameter does not exist, it returns
|
|
// the default value.
|
|
func (r *URLQueryReader) Get(name string, def string) string {
|
|
val := r.values[name]
|
|
if len(val) == 0 {
|
|
return def
|
|
}
|
|
|
|
return val[0]
|
|
}
|
|
|
|
// JoinURLFragments joins two ApiURL fragments into only one ApiURL string.
|
|
func JoinURLFragments(a, b string) string {
|
|
aslash := strings.HasSuffix(a, "/")
|
|
bslash := strings.HasPrefix(b, "/")
|
|
|
|
if len(b) == 0 {
|
|
return a
|
|
}
|
|
|
|
switch {
|
|
case aslash && bslash:
|
|
return a + b[1:]
|
|
case !aslash && !bslash:
|
|
return a + "/" + b
|
|
}
|
|
return a + b
|
|
}
|