本文整理汇总了Golang中github.com/ardanlabs/kit/cfg.Int函数的典型用法代码示例。如果您正苦于以下问题:Golang Int函数的具体用法?Golang Int怎么用?Golang Int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// Initialize the configuration
if err := cfg.Init(cfg.EnvProvider{Namespace: "SPONGE"}); err != nil {
sponge.Println("Unable to initialize configuration")
os.Exit(1)
}
// Initialize the logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.NONE
}
return ll
}
log.Init(os.Stderr, logLevel, log.Ldefault)
sponge.Println("Using log level", logLevel())
// Add the item commands to the CLI tool.
sponge.AddCommand(
cmditem.GetCommands(),
cmdpattern.GetCommands(),
)
// Execute the command.
sponge.Execute()
}
开发者ID:coralproject,项目名称:xenia,代码行数:29,代码来源:main.go
示例2: main
func main() {
if err := cfg.Init(cfg.EnvProvider{Namespace: cfgNamespace}); err != nil {
kit.Println("Unable to initialize configuration")
os.Exit(1)
}
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.NONE
}
return ll
}
log.Init(os.Stderr, logLevel)
cfg := mongo.Config{
Host: cfg.MustString(cfgMongoHost),
AuthDB: cfg.MustString(cfgMongoAuthDB),
DB: cfg.MustString(cfgMongoDB),
User: cfg.MustString(cfgMongoUser),
Password: cfg.MustString(cfgMongoPassword),
}
if err := db.RegMasterSession("startup", cfg.DB, cfg); err != nil {
kit.Println("Unable to initialize MongoDB")
os.Exit(1)
}
kit.AddCommand(
cmdauth.GetCommands(cfg.DB),
cmddb.GetCommands(cfg.DB),
)
kit.Execute()
}
开发者ID:decebal,项目名称:kit,代码行数:34,代码来源:main.go
示例3: init
func init() {
// This is being added to showcase configuration.
os.Setenv("KIT_LOGGING_LEVEL", "1")
os.Setenv("KIT_MIN_ROUTINES", "1")
os.Setenv("KIT_MAX_ROUTINES", "10")
// Init the configuration system.
if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
fmt.Println("Error initalizing configuration system", err)
os.Exit(1)
}
// Init the log system.
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
// Log all the configuration options
log.User("startup", "init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())
}
开发者ID:DmitryZinchenko,项目名称:kit,代码行数:26,代码来源:main.go
示例4: setup
func setup() {
// Save original enviroment variables
oStrategy = os.Getenv("STRATEGY_CONF")
oPillarURL = os.Getenv("PILLAR_URL")
oPollingInterval = os.Getenv("POLLING_INTERVAL")
logLevel := func() int {
ll, err := cfg.Int("LOGGING_LEVEL")
if err != nil {
return log.DEV
}
return ll
}
log.Init(os.Stderr, logLevel)
// MOCK STRATEGY CONF
strategyConf := "../../tests/strategy_test.json"
e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
}
开发者ID:coralproject,项目名称:sponge,代码行数:25,代码来源:sponge_test.go
示例5: Init
// Init is called to initialize the application.
func Init(configKey string) {
// Init the configuration system.
if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
fmt.Println("Error initalizing configuration system", err)
os.Exit(1)
}
// Init the log system.
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
// Log all the configuration options
log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())
// Load user defined custom headers. HEADERS should be key:value,key:value
if hs, err := cfg.String("HEADERS"); err == nil {
hdrs := strings.Split(hs, ",")
for _, hdr := range hdrs {
if kv := strings.Split(hdr, ":"); len(kv) == 2 {
log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1])
app.userHeaders[kv[0]] = kv[1]
}
}
}
}
开发者ID:decebal,项目名称:kit,代码行数:33,代码来源:app.go
示例6: setup
func setup() {
// Save original enviroment variables
oStrategy = os.Getenv("STRATEGY_CONF")
oPillarURL = os.Getenv("PILLAR_URL")
// Initialize log
logLevel := func() int {
ll, err := cfg.Int("LOGGING_LEVEL")
if err != nil {
return log.DEV
}
return ll
}
log.Init(os.Stderr, logLevel)
// Mock strategy configuration
strategyConf := "../../tests/strategy_test.json"
//strategyConf := "../../tests/strategy_with_actions_test.json"
e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
u := uuidimported.New()
// Initialize fiddler
Init(u)
}
开发者ID:coralproject,项目名称:sponge,代码行数:30,代码来源:fiddler_test.go
示例7: main
func main() {
// Initialize logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
// Generate UUID to use with the logs
uid := uuid.New()
if err := sponge.Init(uid); err != nil {
log.Error(uid, "main", err, "Unable to initialize configuration.")
os.Exit(-1)
}
if err := cmd.RootCmd.Execute(); err != nil {
log.Error(uid, "main", err, "Unable to execute the command.")
os.Exit(-1)
}
}
开发者ID:coralproject,项目名称:sponge,代码行数:25,代码来源:main.go
示例8: init
func init() {
logLevel := func() int {
ll, err := cfg.Int("LOGGING_LEVEL")
if err != nil {
return log.DEV
}
return ll
}
log.Init(os.Stderr, logLevel)
}
开发者ID:coralproject,项目名称:sponge,代码行数:11,代码来源:source_test.go
示例9: Init
// Init initializes the log package.
func Init(cfgKey string) {
cfg.Init(cfg.EnvProvider{Namespace: cfgKey})
logLevel := func() int {
ll, err := cfg.Int("LOGGING_LEVEL")
if err != nil {
return log.USER
}
return ll
}
log.Init(&logdash, logLevel)
}
开发者ID:DmitryZinchenko,项目名称:kit,代码行数:13,代码来源:tests.go
示例10: Init
// Init is called to initialize the application.
func Init(configKey string) {
// Init the configuration system.
if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil {
fmt.Println("Error initalizing configuration system", err)
os.Exit(1)
}
// Init the log system.
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
// Log all the configuration options
log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log())
// Init MongoDB if configured.
if _, err := cfg.String(cfgMongoHost); err == nil {
app.useMongo = true
cfg := mongo.Config{
Host: cfg.MustString(cfgMongoHost),
AuthDB: cfg.MustString(cfgMongoAuthDB),
DB: cfg.MustString(cfgMongoDB),
User: cfg.MustString(cfgMongoUser),
Password: cfg.MustString(cfgMongoPassword),
}
if err := mongo.Init(cfg); err != nil {
log.Error("startup", "Init", err, "Initializing MongoDB")
os.Exit(1)
}
}
// Load user defined custom headers. HEADERS should be key:value,key:value
if hs, err := cfg.String("HEADERS"); err == nil {
hdrs := strings.Split(hs, ",")
for _, hdr := range hdrs {
if kv := strings.Split(hdr, ":"); len(kv) == 2 {
log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1])
app.userHeaders[kv[0]] = kv[1]
}
}
}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:51,代码来源:app.go
示例11: Init
// Init sets up the configuration and logging systems.
func Init(p cfg.Provider) {
if err := cfg.Init(p); err != nil {
fmt.Println("Error initalizing configuration system", err)
os.Exit(1)
}
// Init the log system.
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel, log.Ldefault)
}
开发者ID:coralproject,项目名称:xenia,代码行数:17,代码来源:app.go
示例12: setupPostgreSQL
func setupPostgreSQL() {
// Initialize logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
oStrategy = os.Getenv("STRATEGY_CONF")
// MOCK STRATEGY CONF
strategyConf := os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/strategy_discourse_test.json"
e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
var ok bool
u := uuidimported.New()
s, e := Init(u)
if e != nil {
fmt.Printf("Error when initializing strategy, %v.\n", e)
}
m, e := New(s) // setup new source
if e != nil {
fmt.Printf("Error when calling the function, %v.\n", e)
}
mp, ok = m.(PostgreSQL)
if !ok {
fmt.Println("It should return a type PostgreSQL")
}
}
开发者ID:coralproject,项目名称:sponge,代码行数:39,代码来源:source_test.go
示例13: setupMongo
func setupMongo() {
// Initialize logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
oStrategy = os.Getenv("STRATEGY_CONF")
// MOCK STRATEGY CONF
strategyConf := os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/strategy_wapo_test.json"
e := os.Setenv("STRATEGY_CONF", strategyConf)
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
var ok bool
u := uuidimported.New()
s, e := Init(u)
if e != nil {
fmt.Printf("Error when initializing strategy, %v.\n", e)
}
m, e := New(s) // setting up new source
if e != nil {
fmt.Printf("Error when calling the function, %v.\n", e)
}
mdb, ok = m.(MongoDB)
if !ok {
fmt.Println("It should return a type MontoDB")
}
}
开发者ID:coralproject,项目名称:sponge,代码行数:39,代码来源:source_test.go
示例14: TestExists
// TestExists validates the ability to load configuration values
// using the OS-level environment variables and read them back.
func TestExists(t *testing.T) {
t.Log("Given the need to read environment variables.")
{
uStr := "postgres://root:[email protected]:8080/postgres?sslmode=disable"
os.Setenv("MYAPP_PROC_ID", "322")
os.Setenv("MYAPP_SOCKET", "./tmp/sockets.po")
os.Setenv("MYAPP_PORT", "4034")
os.Setenv("MYAPP_FLAG", "true")
os.Setenv("MYAPP_DSN", uStr)
cfg.Init("MYAPP")
t.Log("\tWhen given a namspace key to search for that exists.")
{
proc, err := cfg.Int("PROC_ID")
if err != nil {
t.Errorf("\t\t%s Should not return error when valid key %q", failed, "PROC_ID")
} else {
t.Logf("\t\t%s Should not return error when valid key %q", succeed, "PROC_ID")
if proc != 322 {
t.Errorf("\t\t%s Should have key %q with value %d", failed, "PROC_ID", 322)
} else {
t.Logf("\t\t%s Should have key %q with value %d", succeed, "PROC_ID", 322)
}
}
socket, err := cfg.String("SOCKET")
if err != nil {
t.Errorf("\t\t%s Should not return error when valid key %q", failed, "SOCKET")
} else {
t.Logf("\t\t%s Should not return error when valid key %q", succeed, "SOCKET")
if socket != "./tmp/sockets.po" {
t.Errorf("\t\t%s Should have key %q with value %q", failed, "SOCKET", "./tmp/sockets.po")
} else {
t.Logf("\t\t%s Should have key %q with value %q", succeed, "SOCKET", "./tmp/sockets.po")
}
}
port, err := cfg.Int("PORT")
if err != nil {
t.Errorf("\t\t%s Should not return error when valid key %q", failed, "PORT")
} else {
t.Logf("\t\t%s Should not return error when valid key %q", succeed, "PORT")
if port != 4034 {
t.Errorf("\t\t%s Should have key %q with value %d", failed, "PORT", 4034)
} else {
t.Logf("\t\t%s Should have key %q with value %d", succeed, "PORT", 4034)
}
}
flag, err := cfg.Bool("FLAG")
if err != nil {
t.Errorf("\t\t%s Should not return error when valid key %q", failed, "FLAG")
} else {
t.Logf("\t\t%s Should not return error when valid key %q", succeed, "FLAG")
if flag == false {
t.Errorf("\t\t%s Should have key %q with value %v", failed, "FLAG", true)
} else {
t.Logf("\t\t%s Should have key %q with value %v", succeed, "FLAG", true)
}
}
u, err := cfg.URL("DSN")
if err != nil {
t.Errorf("\t\t%s Should not return error when valid key %q", failed, "DSN")
} else {
t.Logf("\t\t%s Should not return error when valid key %q", succeed, "DSN")
if u.String() != uStr {
t.Errorf("\t\t%s Should have key %q with value %v", failed, "DSN", true)
} else {
t.Logf("\t\t%s Should have key %q with value %v", succeed, "DSN", true)
}
}
}
}
}
开发者ID:coralproject,项目名称:sponge,代码行数:89,代码来源:cfg_test.go
示例15: setup
func setup() {
// Save original enviroment variables
oStrategy = os.Getenv("STRATEGY_CONF")
oPillar = os.Getenv("PILLAR_URL")
logLevel := func() int {
ll, err := cfg.Int("LOGGING_LEVEL")
if err != nil {
return log.DEV
}
return ll
}
log.Init(os.Stderr, logLevel)
//MOCK STRATEGY CONF
strategyConf := "../../tests/strategy_test.json"
e := os.Setenv("STRATEGY_CONF", strategyConf) // IS NOT REALLY SETTING UP THE VARIABLE environment FOR THE WHOLE PROGRAM :(
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
// Initialization of stub server
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
// check that the row is what we want it to be
switch r.RequestURI {
case "/api/import/user": // if user, the payload should be a user kind of payload
// decode the user
user := model.User{}
err = json.NewDecoder(r.Body).Decode(&user)
case "/api/import/asset": // if asset, the payload should be an asset kind of payload
// decode the asset
asset := model.Asset{}
err = json.NewDecoder(r.Body).Decode(&asset)
case "/api/import/comment": // if comment, the payload should be a comment kind of payload
// decode the comment
comment := model.Comment{}
err = json.NewDecoder(r.Body).Decode(&comment)
case "/api/import/index":
// decode the index
index := model.Index{}
err = json.NewDecoder(r.Body).Decode(&index)
default:
err = errors.New("Bad request")
}
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
if err == nil {
w.WriteHeader(http.StatusOK)
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, err)
}))
path = os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/fixtures/"
// Mock pillar url
os.Setenv("PILLAR_URL", server.URL)
u := uuidimported.New()
// Initialize coral
Init(u)
}
开发者ID:coralproject,项目名称:sponge,代码行数:71,代码来源:coral_test.go
示例16: setupAPI
func setupAPI() {
// Mock the API Server
serverurl := mockAPI()
// Initialize logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.USER
}
return ll
}
log.Init(os.Stderr, logLevel)
oStrategy = os.Getenv("STRATEGY_CONF")
// MOCK STRATEGY CONF
strategyConf := os.Getenv("GOPATH") + "/src/github.com/coralproject/sponge/tests/strategy_wapo_api_test.json"
// write down serverurl into the strategyconf
st := strategy
content, err := ioutil.ReadFile(strategyConf)
err = json.Unmarshal(content, &st)
st.Credentials.Service.Endpoint = serverurl
bst, err := json.Marshal(st)
if err != nil {
fmt.Println("Error when trying to marshall back the strategy file with server url of the mock server: ", err)
}
mode := os.FileMode(0777)
err = ioutil.WriteFile(strategyConf, bst, mode)
if err != nil {
fmt.Println("Error when saving back the strategy file with the mock server: ", err)
}
e := os.Setenv("STRATEGY_CONF", strategyConf)
if e != nil {
fmt.Println("It could not setup the mock strategy conf variable")
}
var ok bool
u := uuidimported.New()
s, e := Init(u)
if e != nil {
fmt.Printf("Error when initializing strategy, %v.\n", e)
}
m, e := New(s)
if e != nil {
fmt.Printf("Error when calling the function, %v.\n", e)
}
mapi, ok = m.(API)
if !ok {
fmt.Println("It should return a type API")
}
attributes := "scope:https://www.washingtonpost.com/lifestyle/style/carolyn-hax-stubborn-60-something-parent-refuses-to-see-a-doctor/2015/09/24/299ec776-5e2d-11e5-9757-e49273f05f65_story.html source:washpost.com itemsPerPage:100 sortOrder:reverseChronological"
mapi.Connection = fmt.Sprintf("%s/v1/search?q=((%s))&appkey=dev.washpost.com", serverurl, attributes)
}
开发者ID:coralproject,项目名称:sponge,代码行数:63,代码来源:source_test.go
示例17: TestSets
// TestSets validates the ability to manually set configuration values.
func TestSets(t *testing.T) {
t.Log("Given the need to manually set configuration values.")
{
/*
uStr := "postgres://root:[email protected]:8080/postgres?sslmode=disable"
Map: map[string]string{
"PROC_ID": "322",
"SOCKET": "./tmp/sockets.po",
"PORT": "4034",
"FLAG": "on",
"DSN": uStr,
},
*/
cfg.Init(cfg.MapProvider{
Map: map[string]string{},
})
t.Log("\tWhen setting values.")
{
key := "key1"
strVal := "bill"
cfg.SetString(key, strVal)
retStrVal, err := cfg.String(key)
if err != nil {
t.Errorf("\t\t%s Should find a value for the specified key %q.", failed, key)
} else {
t.Logf("\t\t%s Should find a value for the specified key %q.", success, key)
}
if strVal != retStrVal {
t.Log(strVal)
t.Log(retStrVal)
t.Errorf("\t\t%s Should return the string value %q that was set.", failed, strVal)
} else {
t.Logf("\t\t%s Should return the string value %q that was set.", success, strVal)
}
key = "key2"
intVal := 223
cfg.SetInt(key, intVal)
retIntVal, err := cfg.Int(key)
if err != nil {
t.Errorf("\t\t%s Should find a value for the specified key %q.", failed, key)
} else {
t.Logf("\t\t%s Should find a value for the specified key %q.", success, key)
}
if intVal != retIntVal {
t.Log(intVal)
t.Log(retIntVal)
t.Errorf("\t\t%s Should return the int value %d that was set.", failed, intVal)
} else {
t.Logf("\t\t%s Should return the int value %d that was set.", success, intVal)
}
key = "key3"
timeVal, _ := time.Parse(time.UnixDate, "Mon Oct 27 20:18:15 EST 2016")
cfg.SetTime(key, timeVal)
retTimeVal, err := cfg.Time(key)
if err != nil {
t.Errorf("\t\t%s Should find a value for the specified key %q.", failed, key)
} else {
t.Logf("\t\t%s Should find a value for the specified key %q.", success, key)
}
if timeVal != retTimeVal {
t.Log(timeVal)
t.Log(retTimeVal)
t.Errorf("\t\t%s Should return the time value %q that was set.", failed, timeVal)
} else {
t.Logf("\t\t%s Should return the time value %q that was set.", success, timeVal)
}
key = "key4"
boolVal := true
cfg.SetBool(key, boolVal)
retBoolVal, err := cfg.Bool(key)
if err != nil {
t.Errorf("\t\t%s Should find a value for the specified key %q.", failed, key)
} else {
t.Logf("\t\t%s Should find a value for the specified key %q.", success, key)
}
if boolVal != retBoolVal {
t.Log(boolVal)
t.Log(retBoolVal)
t.Errorf("\t\t%s Should return the bool value \"%v\" that was set.", failed, boolVal)
} else {
t.Logf("\t\t%s Should return the bool value \"%v\" that was set.", success, boolVal)
}
key = "key5"
urlVal, _ := url.Parse("postgres://root:[email protected]:8080/postgres?sslmode=disable")
cfg.SetURL(key, urlVal)
retURLVal, err := cfg.URL(key)
if err != nil {
t.Errorf("\t\t%s Should find a value for the specified key %q.", failed, key)
//.........这里部分代码省略.........
开发者ID:jcbwlkr,项目名称:kit,代码行数:101,代码来源:cfg_test.go
注:本文中的github.com/ardanlabs/kit/cfg.Int函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论