github.com/cs3org/reva/v2@v2.27.7/pkg/storage/utils/indexer/option/option.go (about)

     1  // Copyright 2018-2022 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 option
    20  
    21  import (
    22  	"github.com/cs3org/reva/v2/pkg/storage/utils/metadata"
    23  )
    24  
    25  // Option defines a single option function.
    26  type Option func(o *Options)
    27  
    28  // IndexBy defines how the data is being indexed
    29  type IndexBy interface {
    30  	String() string
    31  }
    32  
    33  // IndexByField represents the field that's being used to index the data by
    34  type IndexByField string
    35  
    36  // String returns a string representation
    37  func (ibf IndexByField) String() string {
    38  	return string(ibf)
    39  }
    40  
    41  // IndexByFunc represents a function that's being used to index the data by
    42  type IndexByFunc struct {
    43  	Name string
    44  	Func func(v interface{}) (string, error)
    45  }
    46  
    47  // String returns a string representation
    48  func (ibf IndexByFunc) String() string {
    49  	return ibf.Name
    50  }
    51  
    52  // Bound represents a lower and upper bound range for an index.
    53  // todo: if we would like to provide an upper bound then we would need to deal with ranges, in which case this is why the
    54  // upper bound attribute is here.
    55  type Bound struct {
    56  	Lower, Upper int64
    57  }
    58  
    59  // Options defines the available options for this package.
    60  type Options struct {
    61  	CaseInsensitive bool
    62  	Bound           *Bound
    63  
    64  	TypeName string
    65  	IndexBy  IndexBy
    66  	FilesDir string
    67  	Prefix   string
    68  
    69  	Storage metadata.Storage
    70  }
    71  
    72  // CaseInsensitive sets the CaseInsensitive field.
    73  func CaseInsensitive(val bool) Option {
    74  	return func(o *Options) {
    75  		o.CaseInsensitive = val
    76  	}
    77  }
    78  
    79  // WithBounds sets the Bounds field.
    80  func WithBounds(val *Bound) Option {
    81  	return func(o *Options) {
    82  		o.Bound = val
    83  	}
    84  }
    85  
    86  // WithTypeName sets the TypeName option.
    87  func WithTypeName(val string) Option {
    88  	return func(o *Options) {
    89  		o.TypeName = val
    90  	}
    91  }
    92  
    93  // WithIndexBy sets the option IndexBy.
    94  func WithIndexBy(val IndexBy) Option {
    95  	return func(o *Options) {
    96  		o.IndexBy = val
    97  	}
    98  }
    99  
   100  // WithFilesDir sets the option FilesDir.
   101  func WithFilesDir(val string) Option {
   102  	return func(o *Options) {
   103  		o.FilesDir = val
   104  	}
   105  }