ms-tester/internal/transport/interceptors.go
Vyacheslav1557 3c0f01630f refactor:
2024-08-16 16:05:29 +05:00

26 lines
567 B
Go

package transport
import (
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type ReqWithToken interface {
GetToken() string
}
func (s *TesterServer) AuthInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
reqWithToken, ok := req.(ReqWithToken)
if !ok {
return nil, status.Errorf(codes.Unknown, "") // FIXME
}
token := reqWithToken.GetToken()
return handler(ctx, req)
}
}