github.com/cs3org/reva/v2@v2.27.7/cmd/revad/runtime/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 runtime
    20  
    21  import (
    22  	"github.com/rs/zerolog"
    23  	"go-micro.dev/v4/registry"
    24  	"go.opentelemetry.io/otel/trace"
    25  )
    26  
    27  // Option defines a single option function.
    28  type Option func(o *Options)
    29  
    30  // Options defines the available options for this package.
    31  type Options struct {
    32  	Logger        *zerolog.Logger
    33  	Registry      registry.Registry
    34  	TraceProvider trace.TracerProvider
    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  // WithLogger provides a function to set the logger option.
    49  func WithLogger(logger *zerolog.Logger) Option {
    50  	return func(o *Options) {
    51  		o.Logger = logger
    52  	}
    53  }
    54  
    55  // WithRegistry provides a function to set the registry.
    56  func WithRegistry(r registry.Registry) Option {
    57  	return func(o *Options) {
    58  		o.Registry = r
    59  	}
    60  }
    61  
    62  // WithTraceProvider provides a function to set the trace provider.
    63  func WithTraceProvider(tp trace.TracerProvider) Option {
    64  	return func(o *Options) {
    65  		o.TraceProvider = tp
    66  	}
    67  }