Skip to content

Instantly share code, notes, and snippets.

@aibou
Created September 9, 2014 08:56
Show Gist options
  • Save aibou/4469dc40f559996c2fac to your computer and use it in GitHub Desktop.
Save aibou/4469dc40f559996c2fac to your computer and use it in GitHub Desktop.
こういう書き方って一般的なのかどうか知りたいです
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