github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/obs/extension.go (about)

     1  // Copyright 2019 Huawei Technologies Co.,Ltd.
     2  // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
     3  // this file except in compliance with the License.  You may obtain a copy of the
     4  // License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software distributed
     9  // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    10  // CONDITIONS OF ANY KIND, either express or implied.  See the License for the
    11  // specific language governing permissions and limitations under the License.
    12  
    13  package obs
    14  
    15  import (
    16  	"fmt"
    17  	"strings"
    18  )
    19  
    20  type extensionOptions interface{}
    21  type extensionHeaders func(headers map[string][]string, isObs bool) error
    22  
    23  func setHeaderPrefix(key string, value string) extensionHeaders {
    24  	return func(headers map[string][]string, isObs bool) error {
    25  		if strings.TrimSpace(value) == "" {
    26  			return fmt.Errorf("set header %s with empty value", key)
    27  		}
    28  		setHeaders(headers, key, []string{value}, isObs)
    29  		return nil
    30  	}
    31  }
    32  
    33  // WithReqPaymentHeader sets header for requester-pays
    34  func WithReqPaymentHeader(requester PayerType) extensionHeaders {
    35  	return setHeaderPrefix(REQUEST_PAYER, string(requester))
    36  }