github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-grpc-middleware/util/metautils/single_key.go (about)

     1  // Copyright 2016 Michal Witkowski. All Rights Reserved.
     2  // See LICENSE for licensing terms.
     3  
     4  package metautils
     5  
     6  import (
     7  	"encoding/base64"
     8  	"strings"
     9  )
    10  
    11  const (
    12  	binHdrSuffix = "-bin"
    13  )
    14  
    15  func encodeKeyValue(k, v string) (string, string) {
    16  	k = strings.ToLower(k)
    17  	if strings.HasSuffix(k, binHdrSuffix) {
    18  		val := base64.StdEncoding.EncodeToString([]byte(v))
    19  		v = string(val)
    20  	}
    21  	return k, v
    22  }