本文整理汇总了Golang中github.com/grafana/grafana/pkg/models.DataSource.Url方法的典型用法代码示例。如果您正苦于以下问题:Golang DataSource.Url方法的具体用法?Golang DataSource.Url怎么用?Golang DataSource.Url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/grafana/grafana/pkg/models.DataSource
的用法示例。
在下文中一共展示了DataSource.Url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewReverseProxy
/**
* @function: func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy
* @description: This function initializes a reverse proxy.
* @related issues: OWL-028, OWL-017, OWL-002
* @param: *m.DataSource ds
* @param: string proxyPath
* @return: *httputil.ReverseProxy
* @author: Don Hsieh
* @since: 07/17/2015
* @last modified: 08/04/2015
* @called by: func ProxyDataSourceRequest(c *middleware.Context)
* in pkg/api/dataproxy.go
*/
func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy {
target, _ := url.Parse(ds.Url)
director := func(req *http.Request) {
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.Host = target.Host
reqQueryVals := req.URL.Query()
if ds.Type == m.DS_INFLUXDB_08 {
req.URL.Path = util.JoinUrlFragments(target.Path, "db/"+ds.Database+"/"+proxyPath)
reqQueryVals.Add("u", ds.User)
reqQueryVals.Add("p", ds.Password)
req.URL.RawQuery = reqQueryVals.Encode()
} else if ds.Type == m.DS_INFLUXDB {
req.URL.Path = util.JoinUrlFragments(target.Path, proxyPath)
reqQueryVals.Add("db", ds.Database)
reqQueryVals.Add("u", ds.User)
reqQueryVals.Add("p", ds.Password)
req.URL.RawQuery = reqQueryVals.Encode()
} else if ds.Type == "openfalcon" {
// fmt.Printf("Welcome to %v!\n", ds.Type)
// fmt.Printf("NewReverseProxy req.URL = %v\n", req.URL)
reqQueryVals.Add("target", ds.Url)
req.URL.RawQuery = reqQueryVals.Encode()
ds.Url = "http://localhost"
var port = "4001"
ds.Url += ":" + port
// fmt.Printf("NewReverseProxy ds.Url = %v\n", ds.Url)
proxyPath = "/"
target, _ := url.Parse(ds.Url)
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.Host = target.Host
req.URL.Path = util.JoinUrlFragments(target.Path, proxyPath)
} else {
req.URL.Path = util.JoinUrlFragments(target.Path, proxyPath)
}
if ds.BasicAuth {
req.Header.Add("Authorization", util.GetBasicAuthHeader(ds.BasicAuthUser, ds.BasicAuthPassword))
}
}
return &httputil.ReverseProxy{Director: director}
}