MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / withGateway

Method withGateway

pkg/gatewayconfigurationserver/http.go:76–96  ·  view source on GitHub ↗
(next func(http.ResponseWriter, *http.Request, *ttnpb.Gateway))

Source from the content-addressed store, hash-verified

74}
75
76func (s *Server) withGateway(next func(http.ResponseWriter, *http.Request, *ttnpb.Gateway)) http.HandlerFunc {
77 return func(w http.ResponseWriter, r *http.Request) {
78 ctx := r.Context()
79 gtwID := gatewayIDFromContext(ctx)
80 cc, err := s.GetPeerConn(ctx, ttnpb.ClusterRole_ENTITY_REGISTRY, nil)
81 if err != nil {
82 webhandlers.Error(w, r, err)
83 return
84 }
85 client := ttnpb.NewGatewayRegistryClient(cc)
86 gtw, err := client.Get(ctx, &ttnpb.GetGatewayRequest{
87 GatewayIds: gtwID,
88 FieldMask: ttnpb.FieldMask("antennas", "frequency_plan_id", "gateway_server_address"),
89 }, s.WithClusterAuth())
90 if err != nil {
91 webhandlers.Error(w, r, err)
92 return
93 }
94 next(w, r, gtw)
95 }
96}
97
98func (s *Server) makeJSONHandler(f func(context.Context, *ttnpb.Gateway) (any, error)) http.HandlerFunc {
99 return s.withGateway(func(w http.ResponseWriter, r *http.Request, gtw *ttnpb.Gateway) {

Callers 2

makeJSONHandlerMethod · 0.95

Calls 8

GetMethod · 0.95
ErrorFunction · 0.92
NewGatewayRegistryClientFunction · 0.92
FieldMaskFunction · 0.92
gatewayIDFromContextFunction · 0.70
ContextMethod · 0.65
GetPeerConnMethod · 0.65
WithClusterAuthMethod · 0.65

Tested by

no test coverage detected