Commit 9fc91b7a by Torkel Ödegaard

fixed gofmt issue

parent 04eefb84
...@@ -64,17 +64,30 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht ...@@ -64,17 +64,30 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht
return &httputil.ReverseProxy{Director: director} return &httputil.ReverseProxy{Director: director}
} }
//ProxyDataSourceRequest TODO need to cache datasources var dsMap map[int64]*m.DataSource = make(map[int64]*m.DataSource)
func ProxyDataSourceRequest(c *middleware.Context) {
id := c.ParamsInt64(":id") func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
query := m.GetDataSourceByIdQuery{Id: id, OrgId: c.OrgId} // ds, exists := dsMap[id]
// if exists && ds.OrgId == orgId {
// return ds, nil
// }
query := m.GetDataSourceByIdQuery{Id: id, OrgId: orgId}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
return nil, err
}
dsMap[id] = &query.Result
return &query.Result, nil
}
func ProxyDataSourceRequest(c *middleware.Context) {
ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId)
if err != nil {
c.JsonApiErr(500, "Unable to load datasource meta data", err) c.JsonApiErr(500, "Unable to load datasource meta data", err)
return return
} }
ds := query.Result
targetUrl, _ := url.Parse(ds.Url) targetUrl, _ := url.Parse(ds.Url)
if len(setting.DataProxyWhiteList) > 0 { if len(setting.DataProxyWhiteList) > 0 {
if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists { if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists {
...@@ -83,11 +96,11 @@ func ProxyDataSourceRequest(c *middleware.Context) { ...@@ -83,11 +96,11 @@ func ProxyDataSourceRequest(c *middleware.Context) {
} }
} }
if query.Result.Type == m.DS_CLOUDWATCH { if ds.Type == m.DS_CLOUDWATCH {
cloudwatch.HandleRequest(c) cloudwatch.HandleRequest(c)
} else { } else {
proxyPath := c.Params("*") proxyPath := c.Params("*")
proxy := NewReverseProxy(&ds, proxyPath, targetUrl) proxy := NewReverseProxy(ds, proxyPath, targetUrl)
proxy.Transport = dataProxyTransport proxy.Transport = dataProxyTransport
proxy.ServeHTTP(c.RW(), c.Req.Request) proxy.ServeHTTP(c.RW(), c.Req.Request)
} }
......
...@@ -18,20 +18,12 @@ package middleware ...@@ -18,20 +18,12 @@ package middleware
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"runtime"
"time" "time"
"github.com/Unknwon/macaron" "github.com/Unknwon/macaron"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
) )
var isWindows bool
func init() {
isWindows = runtime.GOOS == "windows"
}
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
func Logger() macaron.Handler { func Logger() macaron.Handler {
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) { return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
start := time.Now() start := time.Now()
...@@ -40,20 +32,17 @@ func Logger() macaron.Handler { ...@@ -40,20 +32,17 @@ func Logger() macaron.Handler {
c.Next() c.Next()
content := fmt.Sprintf("Completed %s %v %s in %v", req.URL.Path, rw.Status(), http.StatusText(rw.Status()), time.Since(start)) content := fmt.Sprintf("Completed %s %v %s in %v", req.URL.Path, rw.Status(), http.StatusText(rw.Status()), time.Since(start))
if !isWindows {
switch rw.Status() { switch rw.Status() {
case 200: case 200, 304:
content = fmt.Sprintf("\033[1;32m%s\033[0m", content) content = fmt.Sprintf("%s", content)
return
case 304:
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
return return
case 404: case 404:
content = fmt.Sprintf("\033[1;31m%s\033[0m", content) content = fmt.Sprintf("%s", content)
case 500: case 500:
content = fmt.Sprintf("\033[1;36m%s\033[0m", content) content = fmt.Sprintf("%s", content)
}
} }
log.Info(content) log.Info(content)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment