本文整理匯總了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}
}