github.com/scottcagno/storage@v1.8.0/pkg/swal/conf.go (about)

     1  package swal
     2  
     3  const (
     4  	defaultBasePath             = "log"
     5  	defaultMaxSegmentSize int64 = 128 << 10 // 128 KB
     6  	defaultSyncOnWrite          = false
     7  )
     8  
     9  var defaultWALConfig = &SWALConfig{
    10  	BasePath:       defaultBasePath,
    11  	MaxSegmentSize: defaultMaxSegmentSize,
    12  	SyncOnWrite:    defaultSyncOnWrite,
    13  }
    14  
    15  type SWALConfig struct {
    16  	BasePath       string // base storage path
    17  	MaxSegmentSize int64  // max segment size
    18  	SyncOnWrite    bool   // perform sync every write
    19  }
    20  
    21  func checkWALConfig(conf *SWALConfig) *SWALConfig {
    22  	if conf == nil {
    23  		return defaultWALConfig
    24  	}
    25  	if conf.BasePath == *new(string) {
    26  		conf.BasePath = defaultBasePath
    27  	}
    28  	if conf.MaxSegmentSize < 1 {
    29  		conf.MaxSegmentSize = defaultMaxSegmentSize
    30  	}
    31  	return conf
    32  }