linting
This commit is contained in:
@@ -37,7 +37,7 @@ func (i *Imp) initDiscovery(cfg *config) {
|
||||
InvokeURI: cfg.GRPC.DiscoveryInvokeURI(),
|
||||
Version: appversion.Create().Short(),
|
||||
}
|
||||
i.discoveryAnnouncer = discovery.NewAnnouncer(i.logger, producer, string(mservice.PaymentOrchestrator), announce)
|
||||
i.discoveryAnnouncer = discovery.NewAnnouncer(i.logger, producer, mservice.PaymentOrchestrator, announce)
|
||||
i.discoveryAnnouncer.Start()
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ func (r *discoveryClientResolver) findEntry(service mservice.Type, rail string,
|
||||
}
|
||||
|
||||
func discoverySelectionKey(service mservice.Type, rail, network string) string {
|
||||
serviceName := strings.TrimSpace(string(service))
|
||||
serviceName := strings.TrimSpace(service)
|
||||
railName := strings.ToUpper(strings.TrimSpace(rail))
|
||||
networkName := strings.ToUpper(strings.TrimSpace(network))
|
||||
|
||||
@@ -392,10 +392,10 @@ func discoveryEntryKey(entry discovery.RegistryEntry) string {
|
||||
|
||||
func matchesService(service string, candidate mservice.Type) bool {
|
||||
service = strings.TrimSpace(service)
|
||||
if service == "" || strings.TrimSpace(string(candidate)) == "" {
|
||||
if service == "" || strings.TrimSpace(candidate) == "" {
|
||||
return false
|
||||
}
|
||||
return strings.EqualFold(service, strings.TrimSpace(string(candidate)))
|
||||
return strings.EqualFold(service, strings.TrimSpace(candidate))
|
||||
}
|
||||
|
||||
func parseDiscoveryEndpoint(raw string) (discoveryEndpoint, error) {
|
||||
@@ -441,15 +441,12 @@ func parseDiscoveryEndpoint(raw string) (discoveryEndpoint, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func dialGrpc(ctx context.Context, endpoint discoveryEndpoint) (*grpc.ClientConn, error) {
|
||||
func dialGrpc(_ context.Context, endpoint discoveryEndpoint) (*grpc.ClientConn, error) {
|
||||
dialOpts := []grpc.DialOption{}
|
||||
if endpoint.insecure {
|
||||
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
} else {
|
||||
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(nil)))
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return grpc.NewClient(endpoint.address, dialOpts...)
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ func (c *discoveryLedgerClient) Close() error {
|
||||
}
|
||||
client, err := c.resolver.LedgerClient(context.Background())
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
return client.Close()
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func (c *discoveryOracleClient) Close() error {
|
||||
}
|
||||
client, err := c.resolver.OracleClient(context.Background())
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
return client.Close()
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func (c *discoveryChainClient) Close() error {
|
||||
}
|
||||
client, err := c.resolver.ChainClient(context.Background(), c.invokeURI)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
return client.Close()
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func cloneIntentSnapshot(src model.PaymentIntent) (model.PaymentIntent, error) {
|
||||
|
||||
func cloneQuoteSnapshot(src *model.PaymentQuoteSnapshot) (*model.PaymentQuoteSnapshot, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil snapshot means quote data is intentionally absent
|
||||
}
|
||||
dst := &model.PaymentQuoteSnapshot{}
|
||||
if err := bsonClone(src, dst); err != nil {
|
||||
|
||||
@@ -291,7 +291,6 @@ func TestCreate_InputValidation(t *testing.T) {
|
||||
|
||||
factory := New()
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := factory.Create(tt.in)
|
||||
if err == nil {
|
||||
|
||||
@@ -95,8 +95,8 @@ func paginateEntries(items []TimelineEntry, limit int32, desc bool) []TimelineEn
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
if int32(len(items)) > limit {
|
||||
items = items[:limit]
|
||||
if limit > 0 && len(items) > int(limit) {
|
||||
items = items[:int(limit)]
|
||||
}
|
||||
out := make([]TimelineEntry, 0, len(items))
|
||||
for i := range items {
|
||||
|
||||
@@ -229,7 +229,7 @@ func cloneIntentSnapshot(src model.PaymentIntent) (model.PaymentIntent, error) {
|
||||
|
||||
func cloneQuoteSnapshot(src *model.PaymentQuoteSnapshot) (*model.PaymentQuoteSnapshot, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil snapshot means quote data is intentionally absent
|
||||
}
|
||||
dst := &model.PaymentQuoteSnapshot{}
|
||||
if err := bsonClone(src, dst); err != nil {
|
||||
|
||||
@@ -360,11 +360,11 @@ func buildOutput(items []*agg.Payment, limit int32) *ListPaymentsOutput {
|
||||
if len(items) == 0 {
|
||||
return &ListPaymentsOutput{}
|
||||
}
|
||||
if int32(len(items)) > limit {
|
||||
items = items[:limit]
|
||||
if limit > 0 && len(items) > int(limit) {
|
||||
items = items[:int(limit)]
|
||||
}
|
||||
var nextCursor *prepo.ListCursor
|
||||
if int32(len(items)) == limit {
|
||||
if limit > 0 && len(items) == int(limit) {
|
||||
nextCursor = cursorFromPayment(items[len(items)-1])
|
||||
}
|
||||
return &ListPaymentsOutput{
|
||||
|
||||
@@ -32,7 +32,7 @@ func (*paymentDocument) Collection() string {
|
||||
|
||||
func toDocument(payment *agg.Payment) (*paymentDocument, error) {
|
||||
if payment == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil aggregate means no document to persist
|
||||
}
|
||||
doc := &paymentDocument{
|
||||
Base: payment.Base,
|
||||
@@ -52,7 +52,7 @@ func toDocument(payment *agg.Payment) (*paymentDocument, error) {
|
||||
|
||||
func fromDocument(doc *paymentDocument) (*agg.Payment, error) {
|
||||
if doc == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil document means no aggregate to hydrate
|
||||
}
|
||||
cloned, err := cloneDocument(doc)
|
||||
if err != nil {
|
||||
@@ -75,7 +75,7 @@ func fromDocument(doc *paymentDocument) (*agg.Payment, error) {
|
||||
|
||||
func cloneDocument(doc *paymentDocument) (*paymentDocument, error) {
|
||||
if doc == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil document means no clone result
|
||||
}
|
||||
data, err := bson.Marshal(doc)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package prepo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"
|
||||
@@ -62,7 +63,7 @@ func (s *mongoStore) EnsureIndexes(defs []*indexDefinition) error {
|
||||
opt.SetSparse(true)
|
||||
}
|
||||
if def.TTL != nil {
|
||||
opt.SetExpireAfterSeconds(int32(*def.TTL))
|
||||
opt.SetExpireAfterSeconds(*def.TTL)
|
||||
}
|
||||
if def.PartialFilter != nil {
|
||||
opt.SetPartialFilterExpression(def.PartialFilter.BuildQuery())
|
||||
@@ -174,7 +175,7 @@ func (s *mongoStore) findOne(ctx context.Context, filter bson.D) (*paymentDocume
|
||||
if err == nil {
|
||||
return doc, nil
|
||||
}
|
||||
if err == mongo.ErrNoDocuments {
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, ErrPaymentNotFound
|
||||
}
|
||||
return nil, err
|
||||
@@ -206,7 +207,9 @@ func (s *mongoStore) list(ctx context.Context, filter bson.D, cursor *listCursor
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cur.Close(ctx)
|
||||
defer func() {
|
||||
_ = cur.Close(ctx)
|
||||
}()
|
||||
|
||||
items := make([]*paymentDocument, 0)
|
||||
for cur.Next(ctx) {
|
||||
|
||||
@@ -587,7 +587,7 @@ func normalizeStepState(state agg.StepState) (agg.StepState, bool) {
|
||||
|
||||
func normalizeCursor(cursor *ListCursor) (*listCursor, error) {
|
||||
if cursor == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil cursor means pagination starts from first page
|
||||
}
|
||||
if cursor.ID.IsZero() {
|
||||
return nil, merrors.InvalidArgument("cursor.id is required")
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s *svc) Map(in MapInput) (out *MapOutput, err error) {
|
||||
|
||||
func mapPayment(src *agg.Payment) (*orchestrationv2.Payment, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil aggregate means no payment to map
|
||||
}
|
||||
|
||||
intentSnapshot, err := mapIntentSnapshot(src.IntentSnapshot)
|
||||
|
||||
@@ -100,8 +100,8 @@ func (s *svc) transitionAggregateState(current, target agg.State) (agg.State, bo
|
||||
if current == target {
|
||||
return current, true, nil
|
||||
}
|
||||
if err := s.state.EnsureAggregateTransition(current, target); err != nil {
|
||||
return current, false, nil
|
||||
if s.state.EnsureAggregateTransition(current, target) != nil {
|
||||
return current, false, nil //nolint:nilerr // invalid transition is treated as a no-op state update
|
||||
}
|
||||
return target, true, nil
|
||||
}
|
||||
|
||||
@@ -381,8 +381,5 @@ func routeContainsCardPayout(snapshot *model.PaymentQuoteSnapshot) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if model.ParseRail(snapshot.Route.Rail) == discovery.RailCardPayout {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return model.ParseRail(snapshot.Route.Rail) == discovery.RailCardPayout
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (s *svc) ListPayments(ctx context.Context, req *orchestrationv2.ListPayment
|
||||
|
||||
func (s *svc) mapPayments(items []*agg.Payment) ([]*orchestrationv2.Payment, error) {
|
||||
if len(items) == 0 {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil slice means no payments in current page
|
||||
}
|
||||
out := make([]*orchestrationv2.Payment, 0, len(items))
|
||||
for i := range items {
|
||||
@@ -160,7 +160,7 @@ func (s *svc) mapPayment(payment *agg.Payment) (*orchestrationv2.Payment, error)
|
||||
return nil, err
|
||||
}
|
||||
if mapped == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil mapped output means mapper produced no payment payload
|
||||
}
|
||||
return mapped.Payment, nil
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func parsePaymentRef(value string) (string, error) {
|
||||
func parseCursor(value string) (*prepo.ListCursor, error) {
|
||||
raw := strings.TrimSpace(value)
|
||||
if raw == "" {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // empty cursor means pagination starts from first page
|
||||
}
|
||||
data, err := base64.RawURLEncoding.DecodeString(raw)
|
||||
if err != nil {
|
||||
@@ -86,7 +86,7 @@ func formatCursor(cursor *prepo.ListCursor) (string, error) {
|
||||
|
||||
func parseCreated(ts *timestamppb.Timestamp, field string) (*time.Time, error) {
|
||||
if ts == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil timestamp means the filter boundary is not provided
|
||||
}
|
||||
if err := ts.CheckValid(); err != nil {
|
||||
return nil, merrors.InvalidArgument(field + " is invalid")
|
||||
@@ -97,7 +97,7 @@ func parseCreated(ts *timestamppb.Timestamp, field string) (*time.Time, error) {
|
||||
|
||||
func mapStates(states []orchestrationv2.OrchestrationState) ([]agg.State, error) {
|
||||
if len(states) == 0 {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // empty state filter means all states are allowed
|
||||
}
|
||||
out := make([]agg.State, 0, len(states))
|
||||
for i := range states {
|
||||
|
||||
@@ -183,7 +183,6 @@ func TestResolve_InputValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := resolver.Resolve(context.Background(), tt.store, tt.in)
|
||||
if err == nil {
|
||||
|
||||
@@ -290,7 +290,7 @@ func cloneIntentSnapshot(src model.PaymentIntent) (model.PaymentIntent, error) {
|
||||
|
||||
func cloneQuoteSnapshot(src *model.PaymentQuoteSnapshot) (*model.PaymentQuoteSnapshot, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil snapshot means quote data is intentionally absent
|
||||
}
|
||||
dst := &model.PaymentQuoteSnapshot{}
|
||||
if err := bsonClone(src, dst); err != nil {
|
||||
@@ -301,7 +301,7 @@ func cloneQuoteSnapshot(src *model.PaymentQuoteSnapshot) (*model.PaymentQuoteSna
|
||||
|
||||
func cloneStatusSnapshot(src *model.QuoteStatusV2) (*model.QuoteStatusV2, error) {
|
||||
if src == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil snapshot means status data is intentionally absent
|
||||
}
|
||||
dst := &model.QuoteStatusV2{}
|
||||
if err := bsonClone(src, dst); err != nil {
|
||||
|
||||
@@ -200,7 +200,6 @@ func TestValidate_Errors(t *testing.T) {
|
||||
|
||||
v := New()
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx, err := v.Validate(tt.req)
|
||||
if err == nil {
|
||||
|
||||
@@ -209,7 +209,6 @@ func TestCompile_ValidationErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := compiler.Compile(tt.in)
|
||||
if !errors.Is(err, merrors.ErrInvalidArg) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package xplan
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -45,13 +46,5 @@ func railPtr(v model.Rail) *model.Rail {
|
||||
}
|
||||
|
||||
func equalStringSlice(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return slices.Equal(a, b)
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestGatewayCryptoExecutor_ExecuteCrypto_SubmitsWalletFeeTransferOnSend(t *t
|
||||
}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected transfer submission call %d", len(submitRequests))
|
||||
return nil, nil
|
||||
panic("unreachable")
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -366,7 +366,7 @@ func TestGatewayCryptoExecutor_ExecuteCrypto_ResolvesFeeAddressFromFeeWalletRef(
|
||||
}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected transfer submission call %d", len(submitRequests))
|
||||
return nil, nil
|
||||
panic("unreachable")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user