Created
September 9, 2014 08:56
-
-
Save aibou/4469dc40f559996c2fac to your computer and use it in GitHub Desktop.
こういう書き方って一般的なのかどうか知りたいです
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
package main | |
import ( | |
"fmt" | |
"errors" | |
) | |
func hoge() (string, error) { | |
return "hello", errors.New("hello err") | |
} | |
func fuga() (string, error) { | |
return "world", errors.New("world err") | |
} | |
var ( | |
GREET, G_ERR = hoge() | |
WORD, W_ERR = fuga() | |
) | |
func init() { | |
if G_ERR != nil { | |
GREET = "bye" | |
} | |
if W_ERR != nil { | |
WORD = "Tom" | |
} | |
} | |
func main() { | |
fmt.Printf("%s, %s\n", GREET, WORD) | |
// => bye, Tom | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment