Last active
November 5, 2018 05:35
-
-
Save tenntenn/7cd27f699023c259cf781d4f3e4326d5 to your computer and use it in GitHub Desktop.
init関数のふしぎ #golang ref: https://qiita.com/tenntenn/items/7c70e3451ac783999b4f
This file contains hidden or 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" | |
) | |
func init() { | |
fmt.Println("hello, init") | |
} | |
func main() { | |
fmt.Println("Hello, main") | |
} |
This file contains hidden or 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" | |
) | |
func init() { | |
fmt.Println("hello, init") | |
} | |
func main() { | |
fmt.Println("Hello, main") | |
} |
This file contains hidden or 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" | |
) | |
var msg = message() | |
func message() string { | |
return "Hello" | |
} | |
func init() { | |
fmt.Print(msg) | |
} | |
func main() { | |
fmt.Println(", playground") | |
} |
This file contains hidden or 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" | |
) | |
var msg = message() | |
func message() string { | |
return "Hello" | |
} | |
func init() { | |
fmt.Print(msg) | |
} | |
func main() { | |
fmt.Println(", playground") | |
} |
This file contains hidden or 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" | |
) | |
func init() { | |
fmt.Print("hello") | |
} | |
func init() { | |
fmt.Println(", init") | |
} | |
func main() { | |
} |
This file contains hidden or 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" | |
) | |
func init() { | |
fmt.Print("hello") | |
} | |
func init() { | |
fmt.Println(", init") | |
} | |
func main() { | |
} |
This file contains hidden or 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" | |
"runtime" | |
) | |
func init() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} | |
func init() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} | |
func main() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} |
This file contains hidden or 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" | |
"runtime" | |
) | |
func init() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} | |
func init() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} | |
func main() { | |
var pcs [1]uintptr | |
runtime.Callers(1, pcs[:]) | |
fn := runtime.FuncForPC(pcs[0]) | |
fmt.Println(fn.Name()) | |
} |
This file contains hidden or 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
main.init.1 | |
main.init.2 | |
main.main |
This file contains hidden or 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" | |
func init() { | |
fmt.Println("hoge") | |
} | |
func main() { | |
init() | |
} |
This file contains hidden or 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" | |
func init() { | |
fmt.Println("hoge") | |
} | |
func main() { | |
init() | |
} |
This file contains hidden or 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
tmp/sandbox671239315/main.go:10: undefined: init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment