github.com/fern4lvarez/piladb@v0.2.0-alpha.20180407/config/vars/vars.go (about)

     1  // Package vars defines the configuration variables and default values
     2  // for piladb.
     3  package vars
     4  
     5  import "fmt"
     6  
     7  const (
     8  	// MaxStackSize is the maximun number
     9  	// of elements that a stack can contain.
    10  	MaxStackSize = "MAX_STACK_SIZE"
    11  	// MaxStackSizeDefault represents the default value
    12  	// of MaxStackSize.
    13  	MaxStackSizeDefault = -1
    14  
    15  	// ReadTimeout is the maximun duration
    16  	// before timing out the read of a request
    17  	// to pilad.
    18  	ReadTimeout = "READ_TIMEOUT"
    19  	// ReadTimeoutDefault represents the default value
    20  	// of ReadTimeout.
    21  	ReadTimeoutDefault = 30
    22  
    23  	// WriteTimeout is the maximun duration
    24  	// before timing out the write of a response
    25  	// from pilad.
    26  	WriteTimeout = "WRITE_TIMEOUT"
    27  	// WriteTimeoutDefault represents the default value
    28  	// of WriteTimeout.
    29  	WriteTimeoutDefault = 45
    30  
    31  	// ShutdownTimeout is the maximun duration
    32  	// allowed for remaining operations to finish
    33  	// before pilad is shutdown.
    34  	ShutdownTimeout = "SHUTDOWN_TIMEOUT"
    35  	// ShutdownTimeoutDefault represents the default value
    36  	// of ShutdownTimeout.
    37  	ShutdownTimeoutDefault = 15
    38  
    39  	// Port is the TCP port number where pilad
    40  	// is running. Port number range is 1025-65536.
    41  	Port = "PORT"
    42  	// PortDefault represents the default value
    43  	// of Port.
    44  	PortDefault = 1205
    45  
    46  	// PushWhenFull enables to keep pushing elements
    47  	// into a Stack, even if this is full. If this is
    48  	// the case, the base element will be deleted.
    49  	PushWhenFull = "PUSH_WHEN_FULL"
    50  	// PushWhenFullDefault represents the default value
    51  	// of PushWhenFull.
    52  	PushWhenFullDefault = false
    53  
    54  	// NoDonate disables the donation request message
    55  	// on pilad startup.
    56  	NoDonate = "NO_DONATE"
    57  	// NoDonateDefault represents the default value
    58  	// of NoDonate.
    59  	NoDonateDefault = false
    60  )
    61  
    62  // Env returns the environment variable name
    63  // given a config name.
    64  func Env(name string) string {
    65  	return fmt.Sprintf("PILADB_%s", name)
    66  }
    67  
    68  // DefaultInt returns the default value of a config
    69  // name of int type.
    70  func DefaultInt(name string) int {
    71  	switch name {
    72  	case MaxStackSize:
    73  		return MaxStackSizeDefault
    74  	case ReadTimeout:
    75  		return ReadTimeoutDefault
    76  	case WriteTimeout:
    77  		return WriteTimeoutDefault
    78  	case ShutdownTimeout:
    79  		return ShutdownTimeoutDefault
    80  	case Port:
    81  		return PortDefault
    82  	}
    83  	return -1
    84  }
    85  
    86  // DefaultBool returns the default value of a config
    87  // name of boolean type.
    88  func DefaultBool(name string) bool {
    89  	switch name {
    90  	case PushWhenFull:
    91  		return PushWhenFullDefault
    92  	}
    93  	return false
    94  }