github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/ctl/server/http/options.go (about)

     1  // Copyright (c) 2017 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package http
    22  
    23  import (
    24  	"time"
    25  
    26  	"github.com/m3db/m3/src/x/instrument"
    27  )
    28  
    29  const (
    30  	defaultReadTimeout  = 10 * time.Second
    31  	defaultWriteTimeout = 10 * time.Second
    32  )
    33  
    34  // Options is a set of server options.
    35  type Options interface {
    36  	// SetReadTimeout sets the read timeout.
    37  	SetReadTimeout(value time.Duration) Options
    38  
    39  	// ReadTimeout returns the read timeout.
    40  	ReadTimeout() time.Duration
    41  
    42  	// SetWriteTimeout sets the write timeout.
    43  	SetWriteTimeout(value time.Duration) Options
    44  
    45  	// WriteTimeout returns the write timeout.
    46  	WriteTimeout() time.Duration
    47  
    48  	// SetInstrumentOptions returns the write timeout.
    49  	SetInstrumentOptions(value instrument.Options) Options
    50  
    51  	// InstrumentOptions returns the write timeout.
    52  	InstrumentOptions() instrument.Options
    53  }
    54  
    55  type options struct {
    56  	instrumentOpts instrument.Options
    57  	readTimeout    time.Duration
    58  	writeTimeout   time.Duration
    59  }
    60  
    61  // NewOptions creates a new set of server options.
    62  func NewOptions() Options {
    63  	return &options{
    64  		readTimeout:    defaultReadTimeout,
    65  		writeTimeout:   defaultWriteTimeout,
    66  		instrumentOpts: instrument.NewOptions(),
    67  	}
    68  }
    69  
    70  func (o *options) SetInstrumentOptions(value instrument.Options) Options {
    71  	opts := *o
    72  	opts.instrumentOpts = value
    73  	return &opts
    74  }
    75  
    76  func (o *options) InstrumentOptions() instrument.Options {
    77  	return o.instrumentOpts
    78  }
    79  
    80  func (o *options) SetReadTimeout(value time.Duration) Options {
    81  	opts := *o
    82  	opts.readTimeout = value
    83  	return &opts
    84  }
    85  
    86  func (o *options) ReadTimeout() time.Duration {
    87  	return o.readTimeout
    88  }
    89  
    90  func (o *options) SetWriteTimeout(value time.Duration) Options {
    91  	opts := *o
    92  	opts.writeTimeout = value
    93  	return &opts
    94  }
    95  
    96  func (o *options) WriteTimeout() time.Duration {
    97  	return o.writeTimeout
    98  }