mirror of
https://github.com/PretendoNetwork/super-mario-maker.git
synced 2026-09-08 17:07:35 -05:00
Add GRPC server to SMM
This commit is contained in:
26
grpc/api_key_interceptor.go
Normal file
26
grpc/api_key_interceptor.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/PretendoNetwork/super-mario-maker/globals"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func apiKeyInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
|
||||
if ok {
|
||||
apiKeyHeader := md.Get("X-API-Key")
|
||||
|
||||
if len(apiKeyHeader) == 0 || apiKeyHeader[0] != globals.GRPCAPIKey {
|
||||
return nil, errors.New("Missing or invalid API key")
|
||||
}
|
||||
}
|
||||
|
||||
h, err := handler(ctx, req)
|
||||
|
||||
return h, err
|
||||
}
|
||||
Reference in New Issue
Block a user