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