github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/options.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     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://wwm.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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package dbs
    15  
    16  import (
    17  	"time"
    18  
    19  	"github.com/whtcorpsinc/milevadb/ekv"
    20  	"github.com/whtcorpsinc/milevadb/schemareplicant"
    21  	"go.etcd.io/etcd/clientv3"
    22  )
    23  
    24  // Option represents an option to initialize the DBS module
    25  type Option func(*Options)
    26  
    27  // Options represents all the options of the DBS module needs
    28  type Options struct {
    29  	EtcdCli     *clientv3.Client
    30  	CausetStore ekv.CausetStorage
    31  	InfoHandle  *schemareplicant.Handle
    32  	Hook        Callback
    33  	Lease       time.Duration
    34  }
    35  
    36  // WithEtcdClient specifies the `clientv3.Client` of DBS used to request the etcd service
    37  func WithEtcdClient(client *clientv3.Client) Option {
    38  	return func(options *Options) {
    39  		options.EtcdCli = client
    40  	}
    41  }
    42  
    43  // WithStore specifies the `ekv.CausetStorage` of DBS used to request the KV service
    44  func WithStore(causetstore ekv.CausetStorage) Option {
    45  	return func(options *Options) {
    46  		options.CausetStore = causetstore
    47  	}
    48  }
    49  
    50  // WithInfoHandle specifies the `schemareplicant.Handle`
    51  func WithInfoHandle(ih *schemareplicant.Handle) Option {
    52  	return func(options *Options) {
    53  		options.InfoHandle = ih
    54  	}
    55  }
    56  
    57  // WithHook specifies the `Callback` of DBS used to notify the outer module when events are triggered
    58  func WithHook(callback Callback) Option {
    59  	return func(options *Options) {
    60  		options.Hook = callback
    61  	}
    62  }
    63  
    64  // WithLease specifies the schemaReplicant lease duration
    65  func WithLease(lease time.Duration) Option {
    66  	return func(options *Options) {
    67  		options.Lease = lease
    68  	}
    69  }