• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

looplab / eventhorizon / 22671292316

04 Mar 2026 01:24PM UTC coverage: 52.974% (-0.1%) from 53.091%
22671292316

Pull #433

github

web-flow
Merge c45e35d3d into 0a9fd8211
Pull Request #433: Upgrade golangci-lint to v2 and fix all lint issues

120 of 233 new or added lines in 49 files covered. (51.5%)

5 existing lines in 3 files now uncovered.

4319 of 8153 relevant lines covered (52.97%)

58.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/middleware/commandhandler/validate/middleware.go
1
// Copyright (c) 2018 - The Event Horizon authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package validate
16

17
import (
18
        "context"
19

20
        eh "github.com/looplab/eventhorizon"
21
)
22

23
// Command is a command with its own validation method.
24
type Command interface {
25
        eh.Command
26

27
        // Validate returns the error when validating the command.
28
        Validate() error
29
}
30

31
// CommandWithValidation returns a wrapped command with a validation method.
32
func CommandWithValidation(cmd eh.Command, v func() error) Command {
2✔
33
        return &command{Command: cmd, validate: v}
2✔
34
}
2✔
35

36
// NewMiddleware returns a new middleware that validate commands with its own
37
// validation method; `Validate() error`. Commands without the validate method
38
// will not be validated.
39
func NewMiddleware() eh.CommandHandlerMiddleware {
3✔
40
        return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
6✔
41
                return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
6✔
42
                        // Call the validation method if it exists.
3✔
43
                        if c, ok := cmd.(Command); ok {
5✔
44
                                if err := c.Validate(); err != nil {
3✔
45
                                        return &Error{err}
1✔
46
                                }
1✔
47
                        }
48

49
                        // Immediate command execution.
50
                        return h.HandleCommand(ctx, cmd)
2✔
51
                })
52
        })
53
}
54

55
// Error is a validation error.
56
type Error struct {
57
        err error
58
}
59

60
// Error implements the Error method of the error interface.
61
func (e *Error) Error() string {
×
NEW
62
        return "invalid command: " + e.err.Error()
×
63
}
×
64

65
// Unwrap implements the errors.Unwrap method.
66
func (e *Error) Unwrap() error {
1✔
67
        return e.err
1✔
68
}
1✔
69

70
// Cause implements the github.com/pkg/errors Unwrap method.
71
func (e *Error) Cause() error {
×
72
        return e.Unwrap()
×
73
}
×
74

75
// private implementation to wrap ordinary commands and add a validation method.
76
type command struct {
77
        eh.Command
78
        validate func() error
79
}
80

81
// Validate implements the Validate method of the Command interface.
82
func (c *command) Validate() error {
2✔
83
        return c.validate()
2✔
84
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc