github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/grpc_metadata.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package modulecomponents
    13  
    14  import (
    15  	"context"
    16  	"strings"
    17  
    18  	"google.golang.org/grpc/metadata"
    19  )
    20  
    21  func GetValueFromGRPC(ctx context.Context, key string) []string {
    22  	md, ok := metadata.FromIncomingContext(ctx)
    23  	if ok {
    24  		// the grpc library will lowercase all md keys, so we need to make sure to check a lowercase key
    25  		apiKey, ok := md[strings.ToLower(key)]
    26  		if ok {
    27  			return apiKey
    28  		}
    29  	}
    30  	return nil
    31  }