You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

extension.go 1.3 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637
  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. //nolint:golint, unused
  13. package obs
  14. import (
  15. "fmt"
  16. "strings"
  17. )
  18. type extensionOptions interface{}
  19. type extensionHeaders func(headers map[string][]string, isObs bool) error
  20. func setHeaderPrefix(key string, value string) extensionHeaders {
  21. return func(headers map[string][]string, isObs bool) error {
  22. if strings.TrimSpace(value) == "" {
  23. return fmt.Errorf("set header %s with empty value", key)
  24. }
  25. setHeaders(headers, key, []string{value}, isObs)
  26. return nil
  27. }
  28. }
  29. // WithReqPaymentHeader sets header for requester-pays
  30. func WithReqPaymentHeader(requester PayerType) extensionHeaders {
  31. return setHeaderPrefix(REQUEST_PAYER, string(requester))
  32. }