New returns a new Server.
(ctx context.Context, c Component, conf ttgc.Config)
| 53 | |
| 54 | // New returns a new Server. |
| 55 | func New(ctx context.Context, c Component, conf ttgc.Config) (*Server, error) { |
| 56 | srv := &Server{Component: c} |
| 57 | srv.grpc.server = &noopManagedGCSServer{} |
| 58 | srv.grpc.wifiProfiles = &noopManagedGatewayWiFiProfileServer{} |
| 59 | srv.grpc.ethernetProfiles = &noopManagedGatewayEthernetProfileServer{} |
| 60 | |
| 61 | if conf.Enabled { |
| 62 | client, err := ttgc.NewClient(ctx, c, conf) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | srv.grpc.server = &managedGCSServer{ |
| 67 | Component: c, |
| 68 | client: client, |
| 69 | gatewayEUIs: conf.GatewayEUIs, |
| 70 | } |
| 71 | srv.grpc.wifiProfiles = &managedGatewayWiFiProfileServer{ |
| 72 | client: client, |
| 73 | } |
| 74 | srv.grpc.ethernetProfiles = &managedGatewayEthernetProfileServer{ |
| 75 | client: client, |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | c.GRPCServer().RegisterUnaryHook( |
| 80 | "/ttn.lorawan.v3.ManagedGatewayConfigurationService", |
| 81 | rpclog.NamespaceHook, |
| 82 | rpclog.UnaryNamespaceHook("gatewayconfigurationserver/managed"), |
| 83 | ) |
| 84 | c.GRPCServer().RegisterUnaryHook( |
| 85 | "/ttn.lorawan.v3.ManagedGatewayWiFiProfileConfigurationService", |
| 86 | rpclog.NamespaceHook, |
| 87 | rpclog.UnaryNamespaceHook("gatewayconfigurationserver/managed"), |
| 88 | ) |
| 89 | c.GRPCServer().RegisterUnaryHook( |
| 90 | "/ttn.lorawan.v3.ManagedGatewayEthernetProfileConfigurationService", |
| 91 | rpclog.NamespaceHook, |
| 92 | rpclog.UnaryNamespaceHook("gatewayconfigurationserver/managed"), |
| 93 | ) |
| 94 | |
| 95 | return srv, nil |
| 96 | } |
| 97 | |
| 98 | // RegisterServices registers services provided by gcs at s. |
| 99 | func (s *Server) RegisterServices(grpcServer *grpc.Server) { |
no test coverage detected