format hook
This commit is contained in:
parent
002ab7d205
commit
46207396ef
3
.hooks/pre-commit
Executable file
3
.hooks/pre-commit
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
go fmt *.go
|
||||
git add *.go
|
@ -1,7 +1,11 @@
|
||||
package envconf
|
||||
import ("time")
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type DataType int
|
||||
|
||||
const (
|
||||
TypeNone DataType = iota
|
||||
TypeInt DataType = iota
|
||||
@ -28,7 +32,7 @@ func (dtype DataType) parse(key string, str string)(ret cValue) {
|
||||
}
|
||||
return
|
||||
}
|
||||
func (dtype DataType) String()(string) {
|
||||
func (dtype DataType) String() string {
|
||||
info, ok := tInfo[dtype]
|
||||
if ok {
|
||||
return info.name
|
||||
|
26
envconf.go
26
envconf.go
@ -1,11 +1,13 @@
|
||||
package envconf
|
||||
|
||||
import ("strings"
|
||||
"unicode"
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
"fmt"
|
||||
"os")
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type cEntry struct {
|
||||
value string
|
||||
@ -22,7 +24,7 @@ type Config struct {
|
||||
// NewConfig returns an envconf.Config that is used to read configuration from environment variables.
|
||||
// The environment variables are stored in envconf.Config, so changes to the environment after NewConfig has been called
|
||||
// will not be taken into account.
|
||||
func NewConfig()(*Config) {
|
||||
func NewConfig() *Config {
|
||||
config := new(Config)
|
||||
config.parsed = false
|
||||
config.env = make(map[string]cEntry)
|
||||
@ -134,14 +136,14 @@ func (c *Config) getRaw(key string, dtype DataType)(val cValue) {
|
||||
|
||||
// GetInt returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeInt the function will return 0.
|
||||
func (c *Config) GetInt(key string)(int64) {
|
||||
func (c *Config) GetInt(key string) int64 {
|
||||
val := c.getRaw(key, TypeInt)
|
||||
return val.intval
|
||||
}
|
||||
|
||||
// GetMetric returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeMetric the function will return 0.
|
||||
func (c *Config) GetMetric(key string)(int64) {
|
||||
func (c *Config) GetMetric(key string) int64 {
|
||||
val := c.getRaw(key, TypeMetric)
|
||||
return val.intval
|
||||
}
|
||||
@ -149,7 +151,7 @@ func (c *Config) GetMetric(key string)(int64) {
|
||||
// GetDirectory returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeDirectory the
|
||||
// function will return the empty string.
|
||||
func (c *Config) GetDirectory(key string)(string) {
|
||||
func (c *Config) GetDirectory(key string) string {
|
||||
val := c.getRaw(key, TypeDirectory)
|
||||
return val.strval
|
||||
}
|
||||
@ -157,7 +159,7 @@ func (c *Config) GetDirectory(key string)(string) {
|
||||
// GetString returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeString the
|
||||
// function will return the empty string.
|
||||
func (c *Config) GetString(key string)(string) {
|
||||
func (c *Config) GetString(key string) string {
|
||||
val := c.getRaw(key, TypeString)
|
||||
return val.strval
|
||||
}
|
||||
@ -165,7 +167,7 @@ func (c *Config) GetString(key string)(string) {
|
||||
// GetDuration returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeDuration the
|
||||
// function will return time.Duration(0).
|
||||
func (c *Config) GetDuration(key string)(time.Duration) {
|
||||
func (c *Config) GetDuration(key string) time.Duration {
|
||||
val := c.getRaw(key, TypeDuration)
|
||||
return val.durval
|
||||
}
|
||||
@ -173,12 +175,12 @@ func (c *Config) GetDuration(key string)(time.Duration) {
|
||||
// GetBool returns the value of an environment variable.
|
||||
// If the variable is not defined as envconf.TypeBool the
|
||||
// function will return false.
|
||||
func (c *Config) GetBool(key string)(bool) {
|
||||
func (c *Config) GetBool(key string) bool {
|
||||
val := c.getRaw(key, TypeBool)
|
||||
return val.boolval
|
||||
}
|
||||
|
||||
func getFirstRune(str string)(rune) {
|
||||
func getFirstRune(str string) rune {
|
||||
for _, v := range str {
|
||||
return v
|
||||
}
|
||||
|
13
parsers.go
13
parsers.go
@ -1,11 +1,14 @@
|
||||
package envconf
|
||||
import ("strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"time")
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func parseInt(key string, str string) (ret cValue) {
|
||||
val, err := strconv.ParseInt(str, 10, 64)
|
||||
@ -76,9 +79,7 @@ func parseDirectory(_ string, str string)(ret cValue) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func parseString(_ string, str string) (ret cValue) {
|
||||
ret.strval = str
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package envconf
|
||||
|
||||
type dataTypeInfo struct {
|
||||
parser func(string,string)(cValue)
|
||||
parser func(string, string) cValue
|
||||
name string
|
||||
}
|
||||
|
||||
var tInfo map[DataType]dataTypeInfo
|
||||
|
||||
func init() {
|
||||
tInfo = make(map[DataType]dataTypeInfo)
|
||||
var intInfo dataTypeInfo
|
||||
|
Loading…
Reference in New Issue
Block a user