Skip to content

Commit d5d04b9

Browse files
author
Guy Baron
authored
go fmt and go lint error fixes to improve goreportcard (#126)
* go fmt on some files * go fmt * added comments on exported types
1 parent 82eb197 commit d5d04b9

File tree

7 files changed

+27
-13
lines changed

7 files changed

+27
-13
lines changed

gbus/invocation.go

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (dfi *defaultInvocationContext) Log() logrus.FieldLogger {
3232
return dfi.Glogged.Log().WithFields(logrus.Fields{"routing_key": dfi.routingKey, "message_id": dfi.inboundMsg.ID})
3333
}
3434

35+
//Reply implements the Invocation.Reply signature
3536
func (dfi *defaultInvocationContext) Reply(ctx context.Context, replyMessage *BusMessage) error {
3637
if dfi.inboundMsg != nil {
3738
replyMessage.CorrelationID = dfi.inboundMsg.ID
@@ -51,13 +52,15 @@ func (dfi *defaultInvocationContext) Reply(ctx context.Context, replyMessage *Bu
5152
return err
5253
}
5354

55+
//Send implements the Invocation.Send signature
5456
func (dfi *defaultInvocationContext) Send(ctx context.Context, toService string, command *BusMessage, policies ...MessagePolicy) error {
5557
if dfi.tx != nil {
5658
return dfi.bus.sendWithTx(ctx, dfi.tx, toService, command, policies...)
5759
}
5860
return dfi.bus.Send(ctx, toService, command, policies...)
5961
}
6062

63+
//Publish implements the Invocation.Publish signature
6164
func (dfi *defaultInvocationContext) Publish(ctx context.Context, exchange, topic string, event *BusMessage, policies ...MessagePolicy) error {
6265

6366
if dfi.tx != nil {
@@ -66,26 +69,32 @@ func (dfi *defaultInvocationContext) Publish(ctx context.Context, exchange, topi
6669
return dfi.bus.Publish(ctx, exchange, topic, event, policies...)
6770
}
6871

72+
//RPC implements the Invocation.RPC signature
6973
func (dfi *defaultInvocationContext) RPC(ctx context.Context, service string, request, reply *BusMessage, timeout time.Duration) (*BusMessage, error) {
7074
return dfi.bus.RPC(ctx, service, request, reply, timeout)
7175
}
7276

77+
//Bus implements the Invocation.Bus signature
7378
func (dfi *defaultInvocationContext) Bus() Messaging {
7479
return dfi
7580
}
7681

82+
//Tx implements the Invocation.Tx signature
7783
func (dfi *defaultInvocationContext) Tx() *sql.Tx {
7884
return dfi.tx
7985
}
8086

87+
//Ctx implements the Invocation.Ctx signature
8188
func (dfi *defaultInvocationContext) Ctx() context.Context {
8289
return dfi.ctx
8390
}
8491

92+
//Routing implements the Invocation.Routing signature
8593
func (dfi *defaultInvocationContext) Routing() (exchange, routingKey string) {
8694
return dfi.exchange, dfi.routingKey
8795
}
8896

97+
//DeliveryInfo implements the Invocation.DeliveryInfo signature
8998
func (dfi *defaultInvocationContext) DeliveryInfo() DeliveryInfo {
9099
return dfi.deliveryInfo
91100
}

gbus/message_handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
//MessageHandler signature for all command handlers
1010
type MessageHandler func(invocation Invocation, message *BusMessage) error
1111

12+
//Name is a helper function returning the runtime name of the function bound to an instance of the MessageHandler type
1213
func (mg MessageHandler) Name() string {
1314
funName := runtime.FuncForPC(reflect.ValueOf(mg).Pointer()).Name()
1415
splits := strings.Split(funName, ".")

gbus/metrics/handler_metrics.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package metrics
22

33
import (
44
"fmt"
5+
"sync"
6+
57
"github.com/prometheus/client_golang/prometheus"
6-
"github.com/prometheus/client_model/go"
8+
io_prometheus_client "github.com/prometheus/client_model/go"
79
"github.com/sirupsen/logrus"
8-
"sync"
910
)
1011

1112
var (
@@ -20,7 +21,7 @@ const (
2021
grabbitPrefix = "grabbit"
2122
)
2223

23-
type HandlerMetrics struct {
24+
type handlerMetrics struct {
2425
result *prometheus.CounterVec
2526
latency prometheus.Summary
2627
}
@@ -62,17 +63,17 @@ func RunHandlerWithMetric(handleMessage func() error, handlerName string, logger
6263
return err
6364
}
6465

65-
func GetHandlerMetrics(handlerName string) *HandlerMetrics {
66+
func GetHandlerMetrics(handlerName string) *handlerMetrics {
6667
entry, ok := handlerMetricsByHandlerName.Load(handlerName)
6768
if ok {
68-
return entry.(*HandlerMetrics)
69+
return entry.(*handlerMetrics)
6970
}
7071

7172
return nil
7273
}
7374

74-
func newHandlerMetrics(handlerName string) *HandlerMetrics {
75-
return &HandlerMetrics{
75+
func newHandlerMetrics(handlerName string) *handlerMetrics {
76+
return &handlerMetrics{
7677
result: prometheus.NewCounterVec(
7778
prometheus.CounterOpts{
7879
Namespace: grabbitPrefix,
@@ -98,15 +99,15 @@ func trackTime(functionToTrack func() error, observer prometheus.Observer) error
9899
return functionToTrack()
99100
}
100101

101-
func (hm *HandlerMetrics) GetSuccessCount() (float64, error) {
102+
func (hm *handlerMetrics) GetSuccessCount() (float64, error) {
102103
return hm.getLabeledCounterValue(success)
103104
}
104105

105-
func (hm *HandlerMetrics) GetFailureCount() (float64, error) {
106+
func (hm *handlerMetrics) GetFailureCount() (float64, error) {
106107
return hm.getLabeledCounterValue(failure)
107108
}
108109

109-
func (hm *HandlerMetrics) GetLatencySampleCount() (*uint64, error) {
110+
func (hm *handlerMetrics) GetLatencySampleCount() (*uint64, error) {
110111
m := &io_prometheus_client.Metric{}
111112
err := hm.latency.Write(m)
112113
if err != nil {
@@ -116,7 +117,7 @@ func (hm *HandlerMetrics) GetLatencySampleCount() (*uint64, error) {
116117
return m.GetSummary().SampleCount, nil
117118
}
118119

119-
func (hm *HandlerMetrics) getLabeledCounterValue(label string) (float64, error) {
120+
func (hm *handlerMetrics) getLabeledCounterValue(label string) (float64, error) {
120121
m := &io_prometheus_client.Metric{}
121122
err := hm.result.WithLabelValues(label).Write(m)
122123

gbus/metrics/message_metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ func newRejectedMessagesCounter() prometheus.Counter {
3232
Name: "rejected_messages",
3333
Help: "counting the rejected messages",
3434
})
35-
}
35+
}

gbus/metrics/saga_metrics.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
io_prometheus_client "github.com/prometheus/client_model/go"
77
)
88

9+
//SagaTimeoutCounter is the prometheus counter counting timed out saga instances
910
var SagaTimeoutCounter = newSagaTimeoutCounter()
1011

12+
//GetSagaTimeoutCounterValue gets the counter value of timed out sagas reported to prometheus
1113
func GetSagaTimeoutCounterValue() (float64, error) {
1214
m := &io_prometheus_client.Metric{}
1315
err := SagaTimeoutCounter.Write(m)

gbus/outbox.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (out *AMQPOutbox) init(amqp *amqp.Channel, confirm, resendOnNack bool) erro
5050
return nil
5151
}
5252

53+
//Shutdown stops the outbox
5354
func (out *AMQPOutbox) Shutdown() {
5455
close(out.stop)
5556

tests/metrics_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
var (
11-
logger logrus.FieldLogger
11+
logger logrus.FieldLogger
1212
runningTries = 5
1313
)
1414

0 commit comments

Comments
 (0)