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

bavix / gripmock / 21456918549

28 Jan 2026 09:54PM UTC coverage: 48.862% (+0.03%) from 48.832%
21456918549

push

github

web-flow
Merge pull request #727 from bavix/dependabot/go_modules/github.com/zeebo/xxh3-1.1.0

Bump github.com/zeebo/xxh3 from 1.0.2 to 1.1.0

3263 of 6678 relevant lines covered (48.86%)

66.71 hits per line

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

75.29
/cmd/root.go
1
package cmd
2

3
import (
4
        "context"
5
        "net/http"
6
        "os"
7

8
        "github.com/cockroachdb/errors"
9
        "github.com/rs/zerolog"
10
        "github.com/spf13/cobra"
11

12
        "github.com/bavix/gripmock/v3/internal/deps"
13
        "github.com/bavix/gripmock/v3/internal/domain/proto"
14
        "github.com/bavix/gripmock/v3/internal/infra/build"
15
)
16

17
var (
18
        stubFlag    string   //nolint:gochecknoglobals
19
        importsFlag []string //nolint:gochecknoglobals
20
        pluginsFlag []string //nolint:gochecknoglobals
21
)
22

23
var rootCmd = &cobra.Command{ //nolint:gochecknoglobals
24
        Use:     "gripmock",
25
        Short:   "gRPC Mock Server",
26
        Version: build.Version,
27
        Args:    cobra.MinimumNArgs(1),
28
        RunE: func(cmd *cobra.Command, args []string) error {
1✔
29
                builder := deps.NewBuilder(
1✔
30
                        deps.WithDefaultConfig(),
1✔
31
                        deps.WithPlugins(pluginsFlag),
1✔
32
                )
1✔
33
                ctx, cancel := builder.SignalNotify(cmd.Context())
1✔
34
                defer cancel()
1✔
35

1✔
36
                ctx = builder.Logger(ctx)
1✔
37
                builder.LoadPlugins(ctx)
1✔
38

1✔
39
                zerolog.Ctx(ctx).Info().
1✔
40
                        Str("release", build.Version).
1✔
41
                        Msg("Starting GripMock")
1✔
42

1✔
43
                go func() {
2✔
44
                        defer func() {
2✔
45
                                if r := recover(); r != nil {
1✔
46
                                        zerolog.Ctx(ctx).
×
47
                                                Fatal().
×
48
                                                Interface("panic", r).
×
49
                                                Msg("Fatal panic in REST server goroutine - terminating server")
×
50
                                }
×
51
                        }()
52
                        if err := restServe(ctx, builder); err != nil {
1✔
53
                                zerolog.Ctx(ctx).Fatal().Err(err).Msg("Fatal error in REST server - terminating server")
×
54
                        }
×
55
                }()
56

57
                defer builder.Shutdown(context.WithoutCancel(ctx))
1✔
58

1✔
59
                return builder.GRPCServe(ctx, proto.New(args, importsFlag))
1✔
60
        },
61
}
62

63
func restServe(ctx context.Context, builder *deps.Builder) error {
1✔
64
        srv, err := builder.RestServe(ctx, stubFlag)
1✔
65
        if err != nil {
1✔
66
                return errors.Wrap(err, "failed to start rest server")
×
67
        }
×
68

69
        zerolog.Ctx(ctx).Info().Str("addr", srv.Addr).Msg("HTTP server is now running")
1✔
70

1✔
71
        ch := make(chan error)
1✔
72

1✔
73
        go func() {
2✔
74
                defer func() {
2✔
75
                        if r := recover(); r != nil {
1✔
76
                                zerolog.Ctx(ctx).
×
77
                                        Fatal().
×
78
                                        Interface("panic", r).
×
79
                                        Msg("Fatal panic in HTTP server goroutine - terminating server")
×
80
                        }
×
81
                }()
82
                defer close(ch)
1✔
83

1✔
84
                select {
1✔
85
                case <-ctx.Done():
1✔
86
                        if !errors.Is(ctx.Err(), context.Canceled) {
1✔
87
                                ch <- ctx.Err()
×
88
                        }
×
89

90
                        return
1✔
91
                case ch <- srv.ListenAndServe():
×
92
                        return
×
93
                }
94
        }()
95

96
        if err := <-ch; !errors.Is(err, http.ErrServerClosed) {
2✔
97
                return errors.Wrap(err, "http server failed")
1✔
98
        }
1✔
99

100
        return nil
×
101
}
102

103
func init() { //nolint:gochecknoinits
2✔
104
        rootCmd.PersistentFlags().StringVarP(
2✔
105
                &stubFlag,
2✔
106
                "stub",
2✔
107
                "s",
2✔
108
                "",
2✔
109
                "Path where the stub files are (Optional)")
2✔
110

2✔
111
        rootCmd.PersistentFlags().StringSliceVarP(
2✔
112
                &importsFlag,
2✔
113
                "imports",
2✔
114
                "i",
2✔
115
                []string{},
2✔
116
                "Path to import proto-libraries")
2✔
117

2✔
118
        rootCmd.PersistentFlags().StringSliceVar(
2✔
119
                &pluginsFlag,
2✔
120
                "plugins",
2✔
121
                []string{},
2✔
122
                "Template plugin paths (.so)")
2✔
123
}
2✔
124

125
// Execute runs the root command with the given context.
126
func Execute(ctx context.Context) {
2✔
127
        if err := rootCmd.ExecuteContext(ctx); err != nil {
2✔
128
                os.Exit(1)
×
129
        }
×
130
}
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