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
return &httputil.ReverseProxy{Director: director}
}
//ProxyDataSourceRequest TODO need to cache datasources
func ProxyDataSourceRequest(c *middleware.Context) {
id := c.ParamsInt64(":id")
query := m.GetDataSourceByIdQuery{Id: id, OrgId: c.OrgId}
var dsMap map[int64]*m.DataSource = make(map[int64]*m.DataSource)
func getDatasource(id int64, orgId int64) (*m.DataSource, error) {
// 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 {
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)
return
}
ds := query.Result
targetUrl, _ := url.Parse(ds.Url)
if len(setting.DataProxyWhiteList) > 0 {
if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists {
......@@ -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)
} else {
proxyPath := c.Params("*")
proxy := NewReverseProxy(&ds, proxyPath, targetUrl)
proxy := NewReverseProxy(ds, proxyPath, targetUrl)
proxy.Transport = dataProxyTransport
proxy.ServeHTTP(c.RW(), c.Req.Request)
}
......
......@@ -18,20 +18,12 @@ package middleware
import (
"fmt"
"net/http"
"runtime"
"time"
"github.com/Unknwon/macaron"
"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 {
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
start := time.Now()
......@@ -40,20 +32,17 @@ func Logger() macaron.Handler {
c.Next()
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() {
case 200:
content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
return
case 304:
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
case 200, 304:
content = fmt.Sprintf("%s", content)
return
case 404:
content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
content = fmt.Sprintf("%s", content)
case 500:
content = fmt.Sprintf("\033[1;36m%s\033[0m", content)
}
content = fmt.Sprintf("%s", 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