Commit 87760d4f by Mario Trangoni Committed by Carl Bergquist

Codestyle: Fix govet issues (#17178)

ref #10381

Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
parent 574a37e4
...@@ -89,6 +89,7 @@ func GetTestDataScenarios(c *m.ReqContext) Response { ...@@ -89,6 +89,7 @@ func GetTestDataScenarios(c *m.ReqContext) Response {
// Generates a index out of range error // Generates a index out of range error
func GenerateError(c *m.ReqContext) Response { func GenerateError(c *m.ReqContext) Response {
var array []string var array []string
// nolint: govet
return JSON(200, array[20]) return JSON(200, array[20])
} }
......
...@@ -129,11 +129,6 @@ func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPl ...@@ -129,11 +129,6 @@ func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPl
req.URL.Host = targetURL.Host req.URL.Host = targetURL.Host
req.Host = targetURL.Host req.Host = targetURL.Host
req.URL.Path = util.JoinURLFragments(targetURL.Path, proxyPath) req.URL.Path = util.JoinURLFragments(targetURL.Path, proxyPath)
if err != nil {
ctx.JsonApiErr(500, "Could not interpolate plugin route url", err)
return
}
} }
// reqBytes, _ := httputil.DumpRequestOut(req, true); // reqBytes, _ := httputil.DumpRequestOut(req, true);
......
...@@ -6,16 +6,24 @@ import ( ...@@ -6,16 +6,24 @@ import (
"reflect" "reflect"
) )
// HandlerFunc defines a handler function interface.
type HandlerFunc interface{} type HandlerFunc interface{}
// CtxHandlerFunc defines a context handler function.
type CtxHandlerFunc func() type CtxHandlerFunc func()
// Msg defines a message interface.
type Msg interface{} type Msg interface{}
// ErrHandlerNotFound defines an error if a handler is not found
var ErrHandlerNotFound = errors.New("handler not found") var ErrHandlerNotFound = errors.New("handler not found")
// TransactionManager defines a transaction interface
type TransactionManager interface { type TransactionManager interface {
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
} }
// Bus type defines the bus interface structure
type Bus interface { type Bus interface {
Dispatch(msg Msg) error Dispatch(msg Msg) error
DispatchCtx(ctx context.Context, msg Msg) error DispatchCtx(ctx context.Context, msg Msg) error
...@@ -38,10 +46,12 @@ type Bus interface { ...@@ -38,10 +46,12 @@ type Bus interface {
SetTransactionManager(tm TransactionManager) SetTransactionManager(tm TransactionManager)
} }
// InTransaction defines an in transaction function
func (b *InProcBus) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error { func (b *InProcBus) InTransaction(ctx context.Context, fn func(ctx context.Context) error) error {
return b.txMng.InTransaction(ctx, fn) return b.txMng.InTransaction(ctx, fn)
} }
// InProcBus defines the bus structure
type InProcBus struct { type InProcBus struct {
handlers map[string]HandlerFunc handlers map[string]HandlerFunc
handlersWithCtx map[string]HandlerFunc handlersWithCtx map[string]HandlerFunc
...@@ -53,6 +63,7 @@ type InProcBus struct { ...@@ -53,6 +63,7 @@ type InProcBus struct {
// temp stuff, not sure how to handle bus instance, and init yet // temp stuff, not sure how to handle bus instance, and init yet
var globalBus = New() var globalBus = New()
// New initialize the bus
func New() Bus { func New() Bus {
bus := &InProcBus{} bus := &InProcBus{}
bus.handlers = make(map[string]HandlerFunc) bus.handlers = make(map[string]HandlerFunc)
...@@ -69,10 +80,12 @@ func GetBus() Bus { ...@@ -69,10 +80,12 @@ func GetBus() Bus {
return globalBus return globalBus
} }
// SetTransactionManager function assign a transaction manager to the bus.
func (b *InProcBus) SetTransactionManager(tm TransactionManager) { func (b *InProcBus) SetTransactionManager(tm TransactionManager) {
b.txMng = tm b.txMng = tm
} }
// DispatchCtx function dispatch a message to the bus context.
func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error { func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name() var msgName = reflect.TypeOf(msg).Elem().Name()
...@@ -93,6 +106,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error { ...@@ -93,6 +106,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
return err.(error) return err.(error)
} }
// Dispatch function dispatch a message to the bus.
func (b *InProcBus) Dispatch(msg Msg) error { func (b *InProcBus) Dispatch(msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name() var msgName = reflect.TypeOf(msg).Elem().Name()
...@@ -122,6 +136,7 @@ func (b *InProcBus) Dispatch(msg Msg) error { ...@@ -122,6 +136,7 @@ func (b *InProcBus) Dispatch(msg Msg) error {
return err.(error) return err.(error)
} }
// Publish function publish a message to the bus listener.
func (b *InProcBus) Publish(msg Msg) error { func (b *InProcBus) Publish(msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name() var msgName = reflect.TypeOf(msg).Elem().Name()
var listeners = b.listeners[msgName] var listeners = b.listeners[msgName]
...@@ -174,21 +189,25 @@ func (b *InProcBus) AddEventListener(handler HandlerFunc) { ...@@ -174,21 +189,25 @@ func (b *InProcBus) AddEventListener(handler HandlerFunc) {
b.listeners[eventName] = append(b.listeners[eventName], handler) b.listeners[eventName] = append(b.listeners[eventName], handler)
} }
// Package level functions // AddHandler attach a handler function to the global bus
// Package level function
func AddHandler(implName string, handler HandlerFunc) { func AddHandler(implName string, handler HandlerFunc) {
globalBus.AddHandler(handler) globalBus.AddHandler(handler)
} }
// AddHandlerCtx attach a handler function to the global bus context
// Package level functions // Package level functions
func AddHandlerCtx(implName string, handler HandlerFunc) { func AddHandlerCtx(implName string, handler HandlerFunc) {
globalBus.AddHandlerCtx(handler) globalBus.AddHandlerCtx(handler)
} }
// AddEventListener attach a handler function to the event listener
// Package level functions // Package level functions
func AddEventListener(handler HandlerFunc) { func AddEventListener(handler HandlerFunc) {
globalBus.AddEventListener(handler) globalBus.AddEventListener(handler)
} }
// AddWildcardListener attach a handler function to the wildcard listener
func AddWildcardListener(handler HandlerFunc) { func AddWildcardListener(handler HandlerFunc) {
globalBus.AddWildcardListener(handler) globalBus.AddWildcardListener(handler)
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
) )
type testQuery struct { type testQuery struct {
Id int64 ID int64
Resp string Resp string
} }
...@@ -64,9 +64,9 @@ func TestQueryHandlerReturnsError(t *testing.T) { ...@@ -64,9 +64,9 @@ func TestQueryHandlerReturnsError(t *testing.T) {
err := bus.Dispatch(&testQuery{}) err := bus.Dispatch(&testQuery{})
if err == nil { if err == nil {
t.Fatal("Send query failed " + err.Error()) t.Fatal("Send query failed")
} else { } else {
t.Log("Handler error received ok") t.Log("Handler error received ok " + err.Error())
} }
} }
...@@ -93,7 +93,7 @@ func TestEventListeners(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestEventListeners(t *testing.T) {
count := 0 count := 0
bus.AddEventListener(func(query *testQuery) error { bus.AddEventListener(func(query *testQuery) error {
count += 1 count++
return nil return nil
}) })
......
...@@ -56,10 +56,6 @@ func ListAllPlugins(repoUrl string) (m.PluginRepo, error) { ...@@ -56,10 +56,6 @@ func ListAllPlugins(repoUrl string) (m.PluginRepo, error) {
return m.PluginRepo{}, fmt.Errorf("Failed to send request. error: %v", err) return m.PluginRepo{}, fmt.Errorf("Failed to send request. error: %v", err)
} }
if err != nil {
return m.PluginRepo{}, err
}
var data m.PluginRepo var data m.PluginRepo
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err != nil { if err != nil {
...@@ -137,10 +133,6 @@ func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) { ...@@ -137,10 +133,6 @@ func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err) return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err)
} }
if err != nil {
return m.Plugin{}, err
}
var data m.Plugin var data m.Plugin
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err != nil { if err != nil {
......
...@@ -72,10 +72,6 @@ func (az *AzureBlobUploader) Upload(ctx context.Context, imageDiskPath string) ( ...@@ -72,10 +72,6 @@ func (az *AzureBlobUploader) Upload(ctx context.Context, imageDiskPath string) (
return "", aerr return "", aerr
} }
if err != nil {
return "", err
}
url := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", az.account_name, az.container_name, randomFileName) url := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s", az.account_name, az.container_name, randomFileName)
return url, nil return url, nil
} }
......
...@@ -43,16 +43,10 @@ func (s *redisStorage) Get(key string) (interface{}, error) { ...@@ -43,16 +43,10 @@ func (s *redisStorage) Get(key string) (interface{}, error) {
if err == nil { if err == nil {
return item.Val, nil return item.Val, nil
} }
if err.Error() == "EOF" { if err.Error() == "EOF" {
return nil, ErrCacheItemNotFound return nil, ErrCacheItemNotFound
} }
if err != nil {
return nil, err return nil, err
}
return item.Val, nil
} }
// Delete delete a key from session. // Delete delete a key from session.
......
...@@ -244,9 +244,6 @@ func slackFileUpload(evalContext *alerting.EvalContext, log log.Logger, url stri ...@@ -244,9 +244,6 @@ func slackFileUpload(evalContext *alerting.EvalContext, log log.Logger, url stri
log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload") log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload")
return err return err
} }
if err != nil {
return err
}
return nil return nil
} }
......
...@@ -488,9 +488,9 @@ func (cfg *Cfg) loadConfiguration(args *CommandLineArgs) (*ini.File, error) { ...@@ -488,9 +488,9 @@ func (cfg *Cfg) loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
// load specified config file // load specified config file
err = loadSpecifedConfigFile(args.Config, parsedFile) err = loadSpecifedConfigFile(args.Config, parsedFile)
if err != nil { if err != nil {
err = cfg.initLogging(parsedFile) err2 := cfg.initLogging(parsedFile)
if err != nil { if err2 != nil {
return nil, err return nil, err2
} }
log.Fatal(3, err.Error()) log.Fatal(3, err.Error())
} }
......
...@@ -28,6 +28,7 @@ exit_if_fail golangci-lint run --deadline 10m --disable-all \ ...@@ -28,6 +28,7 @@ exit_if_fail golangci-lint run --deadline 10m --disable-all \
--enable=deadcode\ --enable=deadcode\
--enable=gofmt\ --enable=gofmt\
--enable=gosimple\ --enable=gosimple\
--enable=govet\
--enable=ineffassign\ --enable=ineffassign\
--enable=structcheck\ --enable=structcheck\
--enable=unconvert\ --enable=unconvert\
......
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