当前位置: 首页>>代码示例>>Golang>>正文


Golang DataSource.GetHttpTransport方法代码示例

本文整理汇总了Golang中github.com/grafana/grafana/pkg/models.DataSource.GetHttpTransport方法的典型用法代码示例。如果您正苦于以下问题:Golang DataSource.GetHttpTransport方法的具体用法?Golang DataSource.GetHttpTransport怎么用?Golang DataSource.GetHttpTransport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/grafana/grafana/pkg/models.DataSource的用法示例。


在下文中一共展示了DataSource.GetHttpTransport方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewPrometheusExecutor

func NewPrometheusExecutor(dsInfo *models.DataSource) (tsdb.Executor, error) {
	transport, err := dsInfo.GetHttpTransport()
	if err != nil {
		return nil, err
	}

	return &PrometheusExecutor{
		DataSource: dsInfo,
		Transport:  transport,
	}, nil
}
开发者ID:CamJN,项目名称:grafana,代码行数:11,代码来源:prometheus.go

示例2: TestDataSourceProxy

func TestDataSourceProxy(t *testing.T) {
	Convey("When getting graphite datasource proxy", t, func() {
		ds := m.DataSource{Url: "htttp://graphite:8080", Type: m.DS_GRAPHITE}
		targetUrl, err := url.Parse(ds.Url)
		proxy := NewReverseProxy(&ds, "/render", targetUrl)
		proxy.Transport, err = ds.GetHttpTransport()
		So(err, ShouldBeNil)

		transport, ok := proxy.Transport.(*http.Transport)
		So(ok, ShouldBeTrue)
		So(transport.TLSClientConfig.InsecureSkipVerify, ShouldBeTrue)

		requestUrl, _ := url.Parse("http://grafana.com/sub")
		req := http.Request{URL: requestUrl}

		proxy.Director(&req)

		Convey("Can translate request url and path", func() {
			So(req.URL.Host, ShouldEqual, "graphite:8080")
			So(req.URL.Path, ShouldEqual, "/render")
		})
	})

	Convey("When getting influxdb datasource proxy", t, func() {
		ds := m.DataSource{
			Type:     m.DS_INFLUXDB_08,
			Url:      "http://influxdb:8083",
			Database: "site",
			User:     "user",
			Password: "password",
		}

		targetUrl, _ := url.Parse(ds.Url)
		proxy := NewReverseProxy(&ds, "", targetUrl)

		requestUrl, _ := url.Parse("http://grafana.com/sub")
		req := http.Request{URL: requestUrl}

		proxy.Director(&req)

		Convey("Should add db to url", func() {
			So(req.URL.Path, ShouldEqual, "/db/site/")
		})

		Convey("Should add username and password", func() {
			queryVals := req.URL.Query()
			So(queryVals["u"][0], ShouldEqual, "user")
			So(queryVals["p"][0], ShouldEqual, "password")
		})
	})
}
开发者ID:CamJN,项目名称:grafana,代码行数:51,代码来源:dataproxy_test.go


注:本文中的github.com/grafana/grafana/pkg/models.DataSource.GetHttpTransport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。