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

bavix / gripmock / 25203541848

01 May 2026 05:23AM UTC coverage: 72.747% (+0.01%) from 72.735%
25203541848

push

github

web-flow
Merge pull request #853 from bavix/dependabot/go_modules/github.com/klauspost/compress-1.18.6

chore(deps): bump github.com/klauspost/compress from 1.18.5 to 1.18.6

12175 of 16736 relevant lines covered (72.75%)

118.81 hits per line

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

76.67
/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 + " (" + build.Commit + ") " + build.Date,
27
        Args:    cobra.ArbitraryArgs,
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

1✔
34
                ctx, cancel := builder.SignalNotify(cmd.Context())
1✔
35
                defer cancel()
1✔
36

1✔
37
                ctx = builder.Logger(ctx)
1✔
38
                builder.InitTelemetry(ctx)
1✔
39
                builder.LoadPlugins(ctx)
1✔
40

1✔
41
                zerolog.Ctx(ctx).Info().
1✔
42
                        Str("release", build.Version).
1✔
43
                        Str("commit", build.Commit).
1✔
44
                        Str("date", build.Date).
1✔
45
                        Int("pid", os.Getpid()).
1✔
46
                        Msg("Starting GripMock")
1✔
47

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

58
                        if err := restServe(ctx, builder); err != nil {
1✔
59
                                zerolog.Ctx(ctx).Fatal().Err(err).Msg("Fatal error in REST server - terminating server")
×
60
                        }
×
61
                }()
62

63
                defer builder.Shutdown(context.WithoutCancel(ctx))
1✔
64

1✔
65
                return builder.GRPCServe(ctx, proto.New(args, importsFlag))
1✔
66
        },
67
}
68

69
func restServe(ctx context.Context, builder *deps.Builder) error {
1✔
70
        srv, err := builder.RestServe(ctx, stubFlag)
1✔
71
        if err != nil {
1✔
72
                return errors.Wrap(err, "failed to start rest server")
×
73
        }
×
74

75
        zerolog.Ctx(ctx).Info().Str("addr", srv.Addr()).Bool("tls", srv.TLSEnabled()).Msg("HTTP server is now running")
1✔
76

1✔
77
        ch := make(chan error)
1✔
78

1✔
79
        go func() {
2✔
80
                defer func() {
2✔
81
                        if r := recover(); r != nil {
1✔
82
                                zerolog.Ctx(ctx).
×
83
                                        Fatal().
×
84
                                        Interface("panic", r).
×
85
                                        Msg("Fatal panic in HTTP server goroutine - terminating server")
×
86
                        }
×
87
                }()
88
                defer close(ch)
1✔
89

1✔
90
                select {
1✔
91
                case <-ctx.Done():
1✔
92
                        if !errors.Is(ctx.Err(), context.Canceled) {
1✔
93
                                ch <- ctx.Err()
×
94
                        }
×
95

96
                        return
1✔
97
                case ch <- srv.ListenAndServe():
×
98
                        return
×
99
                }
100
        }()
101

102
        if err := <-ch; !errors.Is(err, http.ErrServerClosed) {
2✔
103
                return errors.Wrap(err, "http server failed")
1✔
104
        }
1✔
105

106
        return nil
×
107
}
108

109
func init() { //nolint:gochecknoinits
3✔
110
        rootCmd.PersistentFlags().StringVarP(
3✔
111
                &stubFlag,
3✔
112
                "stub",
3✔
113
                "s",
3✔
114
                "",
3✔
115
                "Path where the stub files are (Optional)")
3✔
116

3✔
117
        rootCmd.PersistentFlags().StringSliceVarP(
3✔
118
                &importsFlag,
3✔
119
                "imports",
3✔
120
                "i",
3✔
121
                []string{},
3✔
122
                "Path to import proto-libraries")
3✔
123

3✔
124
        rootCmd.PersistentFlags().StringSliceVar(
3✔
125
                &pluginsFlag,
3✔
126
                "plugins",
3✔
127
                []string{},
3✔
128
                "Template plugin paths (.so)")
3✔
129
}
3✔
130

131
// Execute runs the root command with the given context.
132
func Execute(ctx context.Context) {
2✔
133
        if err := rootCmd.ExecuteContext(ctx); err != nil {
2✔
134
                os.Exit(1)
×
135
        }
×
136
}
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