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

gatewayd-io / gatewayd / 12498383953

26 Dec 2024 01:45AM UTC coverage: 62.994% (+0.4%) from 62.62%
12498383953

Pull #644

github

mostafa
Fix missing log message and span
Pull Request #644: Refactor commands

870 of 1120 new or added lines in 11 files covered. (77.68%)

33 existing lines in 3 files now uncovered.

5231 of 8304 relevant lines covered (62.99%)

17.13 hits per line

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

72.97
/api/grpc_server.go
1
package api
2

3
import (
4
        "context"
5
        "errors"
6
        "net"
7

8
        v1 "github.com/gatewayd-io/gatewayd/api/v1"
9
        "google.golang.org/grpc"
10
        "google.golang.org/grpc/health/grpc_health_v1"
11
        "google.golang.org/grpc/reflection"
12
)
13

14
type GRPCServer struct {
15
        API        *API
16
        grpcServer *grpc.Server
17
        listener   net.Listener
18
        *HealthChecker
19
}
20

21
// NewGRPCServer creates a new gRPC server.
22
func NewGRPCServer(ctx context.Context, server GRPCServer) *GRPCServer {
2✔
23
        grpcServer, listener := createGRPCAPI(server.API, server.HealthChecker)
2✔
24
        if grpcServer == nil || listener == nil {
2✔
25
                server.API.Options.Logger.Error().Msg("Failed to create gRPC API server and listener")
×
26
                return nil
×
27
        }
×
28

29
        if ctx != nil {
4✔
30
                server.API.ctx = ctx
2✔
31
        } else {
2✔
32
                server.API.ctx = context.Background()
×
33
        }
×
34

35
        return &GRPCServer{
2✔
36
                API:           server.API,
2✔
37
                grpcServer:    grpcServer,
2✔
38
                listener:      listener,
2✔
39
                HealthChecker: server.HealthChecker,
2✔
40
        }
2✔
41
}
42

43
// Start starts the gRPC server.
44
func (s *GRPCServer) Start() {
2✔
45
        if err := s.grpcServer.Serve(s.listener); err != nil && !errors.Is(err, net.ErrClosed) {
2✔
NEW
46
                s.API.Options.Logger.Err(err).Msg("failed to start gRPC API")
×
NEW
47
        }
×
48
}
49

50
// Shutdown shuts down the gRPC server.
51
func (s *GRPCServer) Shutdown(_ context.Context) {
2✔
52
        s.listener.Close()
2✔
53
        s.grpcServer.Stop()
2✔
54
}
2✔
55

56
// createGRPCAPI creates a new gRPC API server and listener.
57
func createGRPCAPI(api *API, healthchecker *HealthChecker) (*grpc.Server, net.Listener) {
2✔
58
        listener, err := net.Listen(api.Options.GRPCNetwork, api.Options.GRPCAddress)
2✔
59
        if err != nil && !errors.Is(err, net.ErrClosed) {
2✔
60
                api.Options.Logger.Err(err).Msg("failed to start gRPC API")
×
61
                return nil, nil
×
62
        }
×
63

64
        grpcServer := grpc.NewServer()
2✔
65
        reflection.Register(grpcServer)
2✔
66
        v1.RegisterGatewayDAdminAPIServiceServer(grpcServer, api)
2✔
67
        grpc_health_v1.RegisterHealthServer(grpcServer, healthchecker)
2✔
68

2✔
69
        return grpcServer, listener
2✔
70
}
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