26 lines
567 B
Go
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)
|
|
}
|
|
}
|