github.com/cs3org/reva/v2@v2.27.7/pkg/rhttp/option.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package rhttp
    20  
    21  import (
    22  	"context"
    23  	"time"
    24  )
    25  
    26  // Option defines a single option function.
    27  type Option func(o *Options)
    28  
    29  // Options defines the available options for this package.
    30  type Options struct {
    31  	Context          context.Context
    32  	Timeout          time.Duration
    33  	Insecure         bool
    34  	DisableKeepAlive bool
    35  }
    36  
    37  // newOptions initializes the available default options.
    38  func newOptions(opts ...Option) Options {
    39  	opt := Options{}
    40  
    41  	for _, o := range opts {
    42  		o(&opt)
    43  	}
    44  
    45  	return opt
    46  }
    47  
    48  // Context provides a function to set the context option.
    49  func Context(val context.Context) Option {
    50  	return func(o *Options) {
    51  		o.Context = val
    52  	}
    53  }
    54  
    55  // Insecure provides a function to set the insecure option.
    56  func Insecure(insecure bool) Option {
    57  	return func(o *Options) {
    58  		o.Insecure = insecure
    59  	}
    60  }
    61  
    62  // Timeout provides a function to set the timeout option.
    63  func Timeout(t time.Duration) Option {
    64  	return func(o *Options) {
    65  		o.Timeout = t
    66  	}
    67  }
    68  
    69  // DisableKeepAlive provides a function to set the disablee keep alive option.
    70  func DisableKeepAlive(disable bool) Option {
    71  	return func(o *Options) {
    72  		o.DisableKeepAlive = disable
    73  	}
    74  }