feat: logging
This commit is contained in:
parent
778d5ef146
commit
fe5e40162b
10 changed files with 151 additions and 75 deletions
|
|
@ -3,7 +3,7 @@ info:
|
|||
title: Swagger GSN - OpenAPI 3.0
|
||||
version: 0.0.1
|
||||
paths:
|
||||
/subscription:
|
||||
/api/v1/subscription:
|
||||
get:
|
||||
tags:
|
||||
- Subscriptions
|
||||
|
|
@ -67,7 +67,7 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/station:
|
||||
/api/v1/station:
|
||||
get:
|
||||
tags:
|
||||
- Stations
|
||||
|
|
@ -106,7 +106,7 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/station/subscribe:
|
||||
/api/v1/station/subscribe:
|
||||
post:
|
||||
tags:
|
||||
- Stations
|
||||
|
|
@ -144,7 +144,7 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/satellite:
|
||||
/api/v1/satellite:
|
||||
get:
|
||||
tags:
|
||||
- Satellites
|
||||
|
|
@ -183,7 +183,7 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/satellite/subscribe:
|
||||
/api/v1/satellite/subscribe:
|
||||
post:
|
||||
tags:
|
||||
- Satellites
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/repository"
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/service"
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/transport/rest"
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/transport/rest/handler"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -14,14 +13,19 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
lg, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repoConfig, err := repository.NewConfig(servicePrefix)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
lg.Fatal("failed to init repo config", zap.Error(err))
|
||||
}
|
||||
|
||||
repo, err := repository.New(repoConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
lg.Fatal("failed to init repo", zap.Error(err))
|
||||
}
|
||||
|
||||
svc := service.New(repo)
|
||||
|
|
@ -30,19 +34,19 @@ func main() {
|
|||
|
||||
restConfig, err := rest.NewConfig(servicePrefix)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
lg.Fatal("failed to init transport config", zap.Error(err))
|
||||
}
|
||||
|
||||
transport, err := rest.New(handler, restConfig)
|
||||
transport, err := rest.New(lg, handler, restConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
lg.Fatal("failed to init transport", zap.Error(err))
|
||||
}
|
||||
|
||||
for {
|
||||
transport.Run()
|
||||
|
||||
if r := recover(); r != nil {
|
||||
log.Println("panic occured: ", r)
|
||||
lg.Warn("panic occured", zap.Any("recover", r))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
internal/pkg/log/log.go
Normal file
23
internal/pkg/log/log.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ctxLogKey struct{}
|
||||
|
||||
func ToCtx(ctx context.Context, lg *zap.Logger) context.Context {
|
||||
return context.WithValue(ctx, ctxLogKey{}, lg)
|
||||
}
|
||||
|
||||
func Ctx(ctx context.Context) *zap.Logger {
|
||||
lg, ok := ctx.Value(ctxLogKey{}).(*zap.Logger)
|
||||
if !ok || lg == nil {
|
||||
zap.L().Error("no logger in context, using global")
|
||||
return zap.L()
|
||||
}
|
||||
|
||||
return lg
|
||||
}
|
||||
44
internal/transport/middleware/log.go
Normal file
44
internal/transport/middleware/log.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/errcodes"
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/pkg/log"
|
||||
"github.com/ogen-go/ogen/middleware"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Logging(logger *zap.Logger) middleware.Middleware {
|
||||
return func(req middleware.Request, next func(req middleware.Request) (middleware.Response, error)) (middleware.Response, error) {
|
||||
lg := logger.With(
|
||||
zap.String("operationId", req.OperationID),
|
||||
)
|
||||
|
||||
lg.Info("started request")
|
||||
|
||||
req.Context = log.ToCtx(req.Context, lg)
|
||||
|
||||
start := time.Now()
|
||||
resp, err := next(req)
|
||||
dur := time.Since(start).Microseconds()
|
||||
|
||||
if err != nil {
|
||||
if errcode, ok := err.(*errcodes.ErrorCode); ok {
|
||||
lg.Error("request error",
|
||||
zap.Int("status_code", errcode.StatusCode),
|
||||
zap.String("message", errcode.Message),
|
||||
zap.String("details", errcode.Details),
|
||||
)
|
||||
} else {
|
||||
lg.Error("request internal error",
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
lg.Info("done request", zap.Float64("duration_ms", float64(dur)/float64(1000)))
|
||||
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
|
@ -2,32 +2,37 @@ package rest
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.intra.yksa.space/gsn/gsn-proxy/internal/transport/middleware"
|
||||
handler "git.intra.yksa.space/gsn/gsn-proxy/internal/transport/rest/handler"
|
||||
api "git.intra.yksa.space/gsn/gsn-proxy/pkg/rest"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Transport struct {
|
||||
lg *zap.Logger
|
||||
cfg *Config
|
||||
srv *api.Server
|
||||
}
|
||||
|
||||
func New(handler *handler.Handler, cfg *Config) (*Transport, error) {
|
||||
srv, err := api.NewServer(handler)
|
||||
func New(lg *zap.Logger, handler *handler.Handler, cfg *Config) (*Transport, error) {
|
||||
srv, err := api.NewServer(handler, api.WithMiddleware(middleware.Logging(lg)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Transport{
|
||||
lg: lg,
|
||||
srv: srv,
|
||||
cfg: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *Transport) Run() {
|
||||
t.lg.Info("started")
|
||||
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", t.cfg.Port), t.srv); err != nil {
|
||||
log.Panic(err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,37 +32,37 @@ type Invoker interface {
|
|||
//
|
||||
// Get available satellites.
|
||||
//
|
||||
// GET /satellite
|
||||
// GET /api/v1/satellite
|
||||
GetSatellites(ctx context.Context) (*GetSatellitesOK, error)
|
||||
// GetStations invokes GetStations operation.
|
||||
//
|
||||
// Get available stations.
|
||||
//
|
||||
// GET /station
|
||||
// GET /api/v1/station
|
||||
GetStations(ctx context.Context) (*GetStationsOK, error)
|
||||
// GetSubscriptions invokes GetSubscriptions operation.
|
||||
//
|
||||
// Get current subscriptions.
|
||||
//
|
||||
// GET /subscription
|
||||
// GET /api/v1/subscription
|
||||
GetSubscriptions(ctx context.Context) (*GetSubscriptionsOK, error)
|
||||
// SubscribeSatellite invokes SubscribeSatellite operation.
|
||||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /satellite/subscribe
|
||||
// POST /api/v1/satellite/subscribe
|
||||
SubscribeSatellite(ctx context.Context, request *SubscribeSatelliteReq) (*SubscribeSatelliteOK, error)
|
||||
// SubscribeStation invokes SubscribeStation operation.
|
||||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /station/subscribe
|
||||
// POST /api/v1/station/subscribe
|
||||
SubscribeStation(ctx context.Context, request *SubscribeStationReq) (*SubscribeStationOK, error)
|
||||
// Unsubscribe invokes Unsubscribe operation.
|
||||
//
|
||||
// Remove subscription by subscription ID.
|
||||
//
|
||||
// DELETE /subscription
|
||||
// DELETE /api/v1/subscription
|
||||
Unsubscribe(ctx context.Context, params UnsubscribeParams) error
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ func (c *Client) requestURL(ctx context.Context) *url.URL {
|
|||
//
|
||||
// Get available satellites.
|
||||
//
|
||||
// GET /satellite
|
||||
// GET /api/v1/satellite
|
||||
func (c *Client) GetSatellites(ctx context.Context) (*GetSatellitesOK, error) {
|
||||
res, err := c.sendGetSatellites(ctx)
|
||||
return res, err
|
||||
|
|
@ -127,7 +127,7 @@ func (c *Client) sendGetSatellites(ctx context.Context) (res *GetSatellitesOK, e
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetSatellites"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/satellite"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/satellite"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -160,7 +160,7 @@ func (c *Client) sendGetSatellites(ctx context.Context) (res *GetSatellitesOK, e
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/satellite"
|
||||
pathParts[0] = "/api/v1/satellite"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeRequest"
|
||||
|
|
@ -189,7 +189,7 @@ func (c *Client) sendGetSatellites(ctx context.Context) (res *GetSatellitesOK, e
|
|||
//
|
||||
// Get available stations.
|
||||
//
|
||||
// GET /station
|
||||
// GET /api/v1/station
|
||||
func (c *Client) GetStations(ctx context.Context) (*GetStationsOK, error) {
|
||||
res, err := c.sendGetStations(ctx)
|
||||
return res, err
|
||||
|
|
@ -199,7 +199,7 @@ func (c *Client) sendGetStations(ctx context.Context) (res *GetStationsOK, err e
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetStations"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/station"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/station"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -232,7 +232,7 @@ func (c *Client) sendGetStations(ctx context.Context) (res *GetStationsOK, err e
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/station"
|
||||
pathParts[0] = "/api/v1/station"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeRequest"
|
||||
|
|
@ -261,7 +261,7 @@ func (c *Client) sendGetStations(ctx context.Context) (res *GetStationsOK, err e
|
|||
//
|
||||
// Get current subscriptions.
|
||||
//
|
||||
// GET /subscription
|
||||
// GET /api/v1/subscription
|
||||
func (c *Client) GetSubscriptions(ctx context.Context) (*GetSubscriptionsOK, error) {
|
||||
res, err := c.sendGetSubscriptions(ctx)
|
||||
return res, err
|
||||
|
|
@ -271,7 +271,7 @@ func (c *Client) sendGetSubscriptions(ctx context.Context) (res *GetSubscription
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetSubscriptions"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/subscription"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/subscription"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -304,7 +304,7 @@ func (c *Client) sendGetSubscriptions(ctx context.Context) (res *GetSubscription
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/subscription"
|
||||
pathParts[0] = "/api/v1/subscription"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeRequest"
|
||||
|
|
@ -333,7 +333,7 @@ func (c *Client) sendGetSubscriptions(ctx context.Context) (res *GetSubscription
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /satellite/subscribe
|
||||
// POST /api/v1/satellite/subscribe
|
||||
func (c *Client) SubscribeSatellite(ctx context.Context, request *SubscribeSatelliteReq) (*SubscribeSatelliteOK, error) {
|
||||
res, err := c.sendSubscribeSatellite(ctx, request)
|
||||
return res, err
|
||||
|
|
@ -343,7 +343,7 @@ func (c *Client) sendSubscribeSatellite(ctx context.Context, request *SubscribeS
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("SubscribeSatellite"),
|
||||
semconv.HTTPRequestMethodKey.String("POST"),
|
||||
semconv.HTTPRouteKey.String("/satellite/subscribe"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/satellite/subscribe"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -376,7 +376,7 @@ func (c *Client) sendSubscribeSatellite(ctx context.Context, request *SubscribeS
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/satellite/subscribe"
|
||||
pathParts[0] = "/api/v1/satellite/subscribe"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeRequest"
|
||||
|
|
@ -408,7 +408,7 @@ func (c *Client) sendSubscribeSatellite(ctx context.Context, request *SubscribeS
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /station/subscribe
|
||||
// POST /api/v1/station/subscribe
|
||||
func (c *Client) SubscribeStation(ctx context.Context, request *SubscribeStationReq) (*SubscribeStationOK, error) {
|
||||
res, err := c.sendSubscribeStation(ctx, request)
|
||||
return res, err
|
||||
|
|
@ -418,7 +418,7 @@ func (c *Client) sendSubscribeStation(ctx context.Context, request *SubscribeSta
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("SubscribeStation"),
|
||||
semconv.HTTPRequestMethodKey.String("POST"),
|
||||
semconv.HTTPRouteKey.String("/station/subscribe"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/station/subscribe"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -451,7 +451,7 @@ func (c *Client) sendSubscribeStation(ctx context.Context, request *SubscribeSta
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/station/subscribe"
|
||||
pathParts[0] = "/api/v1/station/subscribe"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeRequest"
|
||||
|
|
@ -483,7 +483,7 @@ func (c *Client) sendSubscribeStation(ctx context.Context, request *SubscribeSta
|
|||
//
|
||||
// Remove subscription by subscription ID.
|
||||
//
|
||||
// DELETE /subscription
|
||||
// DELETE /api/v1/subscription
|
||||
func (c *Client) Unsubscribe(ctx context.Context, params UnsubscribeParams) error {
|
||||
_, err := c.sendUnsubscribe(ctx, params)
|
||||
return err
|
||||
|
|
@ -493,7 +493,7 @@ func (c *Client) sendUnsubscribe(ctx context.Context, params UnsubscribeParams)
|
|||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("Unsubscribe"),
|
||||
semconv.HTTPRequestMethodKey.String("DELETE"),
|
||||
semconv.HTTPRouteKey.String("/subscription"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/subscription"),
|
||||
}
|
||||
|
||||
// Run stopwatch.
|
||||
|
|
@ -526,7 +526,7 @@ func (c *Client) sendUnsubscribe(ctx context.Context, params UnsubscribeParams)
|
|||
stage = "BuildURL"
|
||||
u := uri.Clone(c.requestURL(ctx))
|
||||
var pathParts [1]string
|
||||
pathParts[0] = "/subscription"
|
||||
pathParts[0] = "/api/v1/subscription"
|
||||
uri.AddPathParts(u, pathParts[:]...)
|
||||
|
||||
stage = "EncodeQueryParams"
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ func (c *codeRecorder) WriteHeader(status int) {
|
|||
//
|
||||
// Get available satellites.
|
||||
//
|
||||
// GET /satellite
|
||||
// GET /api/v1/satellite
|
||||
func (s *Server) handleGetSatellitesRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetSatellites"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/satellite"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/satellite"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
@ -164,14 +164,14 @@ func (s *Server) handleGetSatellitesRequest(args [0]string, argsEscaped bool, w
|
|||
//
|
||||
// Get available stations.
|
||||
//
|
||||
// GET /station
|
||||
// GET /api/v1/station
|
||||
func (s *Server) handleGetStationsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetStations"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/station"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/station"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
@ -294,14 +294,14 @@ func (s *Server) handleGetStationsRequest(args [0]string, argsEscaped bool, w ht
|
|||
//
|
||||
// Get current subscriptions.
|
||||
//
|
||||
// GET /subscription
|
||||
// GET /api/v1/subscription
|
||||
func (s *Server) handleGetSubscriptionsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("GetSubscriptions"),
|
||||
semconv.HTTPRequestMethodKey.String("GET"),
|
||||
semconv.HTTPRouteKey.String("/subscription"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/subscription"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
@ -424,14 +424,14 @@ func (s *Server) handleGetSubscriptionsRequest(args [0]string, argsEscaped bool,
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /satellite/subscribe
|
||||
// POST /api/v1/satellite/subscribe
|
||||
func (s *Server) handleSubscribeSatelliteRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("SubscribeSatellite"),
|
||||
semconv.HTTPRequestMethodKey.String("POST"),
|
||||
semconv.HTTPRouteKey.String("/satellite/subscribe"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/satellite/subscribe"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
@ -573,14 +573,14 @@ func (s *Server) handleSubscribeSatelliteRequest(args [0]string, argsEscaped boo
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /station/subscribe
|
||||
// POST /api/v1/station/subscribe
|
||||
func (s *Server) handleSubscribeStationRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("SubscribeStation"),
|
||||
semconv.HTTPRequestMethodKey.String("POST"),
|
||||
semconv.HTTPRouteKey.String("/station/subscribe"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/station/subscribe"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
@ -722,14 +722,14 @@ func (s *Server) handleSubscribeStationRequest(args [0]string, argsEscaped bool,
|
|||
//
|
||||
// Remove subscription by subscription ID.
|
||||
//
|
||||
// DELETE /subscription
|
||||
// DELETE /api/v1/subscription
|
||||
func (s *Server) handleUnsubscribeRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
||||
w = statusWriter
|
||||
otelAttrs := []attribute.KeyValue{
|
||||
otelogen.OperationID("Unsubscribe"),
|
||||
semconv.HTTPRequestMethodKey.String("DELETE"),
|
||||
semconv.HTTPRouteKey.String("/subscription"),
|
||||
semconv.HTTPRouteKey.String("/api/v1/subscription"),
|
||||
}
|
||||
|
||||
// Start a span for this request.
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/s"
|
||||
case '/': // Prefix: "/api/v1/s"
|
||||
|
||||
if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" {
|
||||
if l := len("/api/v1/s"); len(elem) >= l && elem[0:l] == "/api/v1/s" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
|
|
@ -246,9 +246,9 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/s"
|
||||
case '/': // Prefix: "/api/v1/s"
|
||||
|
||||
if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" {
|
||||
if l := len("/api/v1/s"); len(elem) >= l && elem[0:l] == "/api/v1/s" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
|
|
@ -272,7 +272,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = GetSatellitesOperation
|
||||
r.summary = "Get available satellites"
|
||||
r.operationID = "GetSatellites"
|
||||
r.pathPattern = "/satellite"
|
||||
r.pathPattern = "/api/v1/satellite"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
@ -296,7 +296,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = SubscribeSatelliteOperation
|
||||
r.summary = "Subscribe to a given station"
|
||||
r.operationID = "SubscribeSatellite"
|
||||
r.pathPattern = "/satellite/subscribe"
|
||||
r.pathPattern = "/api/v1/satellite/subscribe"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
@ -321,7 +321,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = GetStationsOperation
|
||||
r.summary = "Get available stations"
|
||||
r.operationID = "GetStations"
|
||||
r.pathPattern = "/station"
|
||||
r.pathPattern = "/api/v1/station"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
@ -345,7 +345,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = SubscribeStationOperation
|
||||
r.summary = "Subscribe to a given station"
|
||||
r.operationID = "SubscribeStation"
|
||||
r.pathPattern = "/station/subscribe"
|
||||
r.pathPattern = "/api/v1/station/subscribe"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
@ -371,7 +371,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = UnsubscribeOperation
|
||||
r.summary = "Remove subscription by subscription ID"
|
||||
r.operationID = "Unsubscribe"
|
||||
r.pathPattern = "/subscription"
|
||||
r.pathPattern = "/api/v1/subscription"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
@ -379,7 +379,7 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
|||
r.name = GetSubscriptionsOperation
|
||||
r.summary = "Get current subscriptions"
|
||||
r.operationID = "GetSubscriptions"
|
||||
r.pathPattern = "/subscription"
|
||||
r.pathPattern = "/api/v1/subscription"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
|
|
|
|||
|
|
@ -12,37 +12,37 @@ type Handler interface {
|
|||
//
|
||||
// Get available satellites.
|
||||
//
|
||||
// GET /satellite
|
||||
// GET /api/v1/satellite
|
||||
GetSatellites(ctx context.Context) (*GetSatellitesOK, error)
|
||||
// GetStations implements GetStations operation.
|
||||
//
|
||||
// Get available stations.
|
||||
//
|
||||
// GET /station
|
||||
// GET /api/v1/station
|
||||
GetStations(ctx context.Context) (*GetStationsOK, error)
|
||||
// GetSubscriptions implements GetSubscriptions operation.
|
||||
//
|
||||
// Get current subscriptions.
|
||||
//
|
||||
// GET /subscription
|
||||
// GET /api/v1/subscription
|
||||
GetSubscriptions(ctx context.Context) (*GetSubscriptionsOK, error)
|
||||
// SubscribeSatellite implements SubscribeSatellite operation.
|
||||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /satellite/subscribe
|
||||
// POST /api/v1/satellite/subscribe
|
||||
SubscribeSatellite(ctx context.Context, req *SubscribeSatelliteReq) (*SubscribeSatelliteOK, error)
|
||||
// SubscribeStation implements SubscribeStation operation.
|
||||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /station/subscribe
|
||||
// POST /api/v1/station/subscribe
|
||||
SubscribeStation(ctx context.Context, req *SubscribeStationReq) (*SubscribeStationOK, error)
|
||||
// Unsubscribe implements Unsubscribe operation.
|
||||
//
|
||||
// Remove subscription by subscription ID.
|
||||
//
|
||||
// DELETE /subscription
|
||||
// DELETE /api/v1/subscription
|
||||
Unsubscribe(ctx context.Context, params UnsubscribeParams) error
|
||||
// NewError creates *ErrorStatusCode from error returned by handler.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ var _ Handler = UnimplementedHandler{}
|
|||
//
|
||||
// Get available satellites.
|
||||
//
|
||||
// GET /satellite
|
||||
// GET /api/v1/satellite
|
||||
func (UnimplementedHandler) GetSatellites(ctx context.Context) (r *GetSatellitesOK, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ func (UnimplementedHandler) GetSatellites(ctx context.Context) (r *GetSatellites
|
|||
//
|
||||
// Get available stations.
|
||||
//
|
||||
// GET /station
|
||||
// GET /api/v1/station
|
||||
func (UnimplementedHandler) GetStations(ctx context.Context) (r *GetStationsOK, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ func (UnimplementedHandler) GetStations(ctx context.Context) (r *GetStationsOK,
|
|||
//
|
||||
// Get current subscriptions.
|
||||
//
|
||||
// GET /subscription
|
||||
// GET /api/v1/subscription
|
||||
func (UnimplementedHandler) GetSubscriptions(ctx context.Context) (r *GetSubscriptionsOK, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ func (UnimplementedHandler) GetSubscriptions(ctx context.Context) (r *GetSubscri
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /satellite/subscribe
|
||||
// POST /api/v1/satellite/subscribe
|
||||
func (UnimplementedHandler) SubscribeSatellite(ctx context.Context, req *SubscribeSatelliteReq) (r *SubscribeSatelliteOK, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func (UnimplementedHandler) SubscribeSatellite(ctx context.Context, req *Subscri
|
|||
//
|
||||
// Subscribe to a given station.
|
||||
//
|
||||
// POST /station/subscribe
|
||||
// POST /api/v1/station/subscribe
|
||||
func (UnimplementedHandler) SubscribeStation(ctx context.Context, req *SubscribeStationReq) (r *SubscribeStationOK, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func (UnimplementedHandler) SubscribeStation(ctx context.Context, req *Subscribe
|
|||
//
|
||||
// Remove subscription by subscription ID.
|
||||
//
|
||||
// DELETE /subscription
|
||||
// DELETE /api/v1/subscription
|
||||
func (UnimplementedHandler) Unsubscribe(ctx context.Context, params UnsubscribeParams) error {
|
||||
return ht.ErrNotImplemented
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue