github.com/status-im/status-go@v1.1.0/protocol/messenger_store_node_request_manager_config.go (about)

     1  package protocol
     2  
     3  type StoreNodeRequestConfig struct {
     4  	WaitForResponse   bool
     5  	StopWhenDataFound bool
     6  	InitialPageSize   uint32
     7  	FurtherPageSize   uint32
     8  }
     9  
    10  type StoreNodeRequestOption func(*StoreNodeRequestConfig)
    11  
    12  func defaultStoreNodeRequestConfig() StoreNodeRequestConfig {
    13  	return StoreNodeRequestConfig{
    14  		WaitForResponse:   true,
    15  		StopWhenDataFound: true,
    16  		InitialPageSize:   initialStoreNodeRequestPageSize,
    17  		FurtherPageSize:   defaultStoreNodeRequestPageSize,
    18  	}
    19  }
    20  
    21  func buildStoreNodeRequestConfig(opts []StoreNodeRequestOption) StoreNodeRequestConfig {
    22  	cfg := defaultStoreNodeRequestConfig()
    23  
    24  	for _, opt := range opts {
    25  		opt(&cfg)
    26  	}
    27  
    28  	return cfg
    29  }
    30  
    31  func WithWaitForResponseOption(waitForResponse bool) StoreNodeRequestOption {
    32  	return func(c *StoreNodeRequestConfig) {
    33  		c.WaitForResponse = waitForResponse
    34  	}
    35  }
    36  
    37  func WithStopWhenDataFound(stopWhenDataFound bool) StoreNodeRequestOption {
    38  	return func(c *StoreNodeRequestConfig) {
    39  		c.StopWhenDataFound = stopWhenDataFound
    40  	}
    41  }
    42  
    43  func WithInitialPageSize(initialPageSize uint32) StoreNodeRequestOption {
    44  	return func(c *StoreNodeRequestConfig) {
    45  		c.InitialPageSize = initialPageSize
    46  	}
    47  }
    48  
    49  func WithFurtherPageSize(furtherPageSize uint32) StoreNodeRequestOption {
    50  	return func(c *StoreNodeRequestConfig) {
    51  		c.FurtherPageSize = furtherPageSize
    52  	}
    53  }