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

looplab / eventhorizon / 26145686527

20 May 2026 06:32AM UTC coverage: 52.962% (-0.1%) from 53.091%
26145686527

push

github

web-flow
Merge pull request #433 from looplab/feat/golangci-lint-upgrade

Upgrade golangci-lint to v2 and fix all lint issues

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

6 existing lines in 4 files now uncovered.

4318 of 8153 relevant lines covered (52.96%)

58.93 hits per line

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

0.0
/httputils/command.go
1
// Copyright (c) 2017 - 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 httputils
16

17
import (
18
        "context"
19
        "encoding/json"
20
        "io"
21
        "net/http"
22

23
        eh "github.com/looplab/eventhorizon"
24
)
25

26
// CommandHandler is a HTTP handler for eventhorizon.Commands. Commands must be
27
// registered with eventhorizon.RegisterCommand(). It expects a POST with a JSON
28
// body that will be unmarshaled into the command.
29
func CommandHandler(commandHandler eh.CommandHandler, commandType eh.CommandType) http.Handler {
×
30
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
×
NEW
31
                if r.Method != http.MethodPost {
×
32
                        http.Error(w, "unsupported method: "+r.Method, http.StatusMethodNotAllowed)
×
33

×
34
                        return
×
35
                }
×
36

37
                cmd, err := eh.CreateCommand(commandType)
×
38
                if err != nil {
×
39
                        http.Error(w, "could not create command: "+err.Error(), http.StatusBadRequest)
×
40

×
41
                        return
×
42
                }
×
43

NEW
44
                b, err := io.ReadAll(r.Body)
×
45
                if err != nil {
×
46
                        http.Error(w, "could not read command: "+err.Error(), http.StatusBadRequest)
×
47

×
48
                        return
×
49
                }
×
50

51
                if err := json.Unmarshal(b, &cmd); err != nil {
×
52
                        http.Error(w, "could not decode command: "+err.Error(), http.StatusBadRequest)
×
53

×
54
                        return
×
55
                }
×
56

57
                // NOTE: Use a new context when handling, else it will be cancelled with
58
                // the HTTP request which will cause projectors etc to fail if they run
59
                // async in goroutines past the request.
60
                ctx := context.Background()
×
NEW
61
                if err := commandHandler.HandleCommand(ctx, cmd); err != nil { //nolint:contextcheck // command handling must outlive the HTTP request
×
62
                        http.Error(w, "could not handle command: "+err.Error(), http.StatusBadRequest)
×
63

×
64
                        return
×
65
                }
×
66

67
                w.WriteHeader(http.StatusOK)
×
68
        })
69
}
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