-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ieee0824/refactor
リファクタリング
- Loading branch information
Showing
5 changed files
with
68 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package getenv | ||
|
||
import ( | ||
"strings" | ||
"os" | ||
) | ||
|
||
func convertStringToBoolean(s string) bool { | ||
s = strings.ToLower(s) | ||
switch s { | ||
case "true", "t", "1": | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func Bool(key string, def ...bool) bool { | ||
var d bool | ||
if len(def) != 0 { | ||
d = def[0] | ||
} else { | ||
d = false | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
return convertStringToBoolean(v) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1 @@ | ||
package getenv | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"strconv" | ||
) | ||
|
||
func convertStringToBoolean(s string) bool { | ||
s = strings.ToLower(s) | ||
switch s { | ||
case "true", "t", "1": | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func Bool(key string, def ...bool) bool { | ||
var d bool | ||
if len(def) != 0 { | ||
d = def[0] | ||
} else { | ||
d = false | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
return convertStringToBoolean(v) | ||
} | ||
|
||
func String(key string, def ...string) string { | ||
var d string | ||
if len(def) != 0 { | ||
d = def[0] | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
return v | ||
} | ||
|
||
func Int(key string, def ...int) int { | ||
var d int | ||
if len(def) != 0 { | ||
d = def[0] | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
i, err := strconv.Atoi(v) | ||
if err != nil { | ||
return d | ||
} | ||
return i | ||
} | ||
|
||
package getenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package getenv | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func Int(key string, def ...int) int { | ||
var d int | ||
if len(def) != 0 { | ||
d = def[0] | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
i, err := strconv.Atoi(v) | ||
if err != nil { | ||
return d | ||
} | ||
return i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package getenv | ||
|
||
import "os" | ||
|
||
func String(key string, def ...string) string { | ||
var d string | ||
if len(def) != 0 { | ||
d = def[0] | ||
} | ||
v := os.Getenv(key) | ||
if v == "" { | ||
return d | ||
} | ||
return v | ||
} |