Keybase proof
I hereby claim:
- I am christophberger on github.
- I am christophberger (https://keybase.io/christophberger) on keybase.
- I have a public key ASC8b-gcdQzzyAjieAUZNehGbw2z1Fd2V2xp8SduLfHYxAo
To claim this, I am signing this object:
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
c := make(chan int) |
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
x := make([]int, 1, 10) | |
var a []int |
The Package reflect in the Go standard library implements run-time reflection, allowing a program to manipulate objects with arbitrary types. | |
We can build with the reflection package a kind of generic functionality. Because this package give us the possibility to determine the meta information of a function and it's input and output arguments while runtime. | |
Be careful when you start to use the reflection package it's hard to debug run time errors. For more information about reflection, I can recommend the following article about reflection. | |
See "The Laws of Reflection" for an introduction to reflection in Go: https://golang.org/doc/articles/laws_of_reflection.html | |
If you want see reflection in action below is a example: | |
func main() { | |
if len(os.Args) <= 1 { | |
log.Println("Usage: go run tui.go [termui|gocui]") | |
return | |
} | |
if os.Args[1] == "termui" { | |
runTermui() | |
return | |
} | |
if os.Args[1] == "gocui" { |
func runGocui() { | |
// Create a new GUI. | |
g, err := c.NewGui(c.OutputNormal) | |
if err != nil { | |
log.Println("Failed to create a GUI:", err) | |
return | |
} | |
defer g.Close() | |
// Activate the cursor for the current view. |
func runTermui() { | |
// Initialize termui. | |
err := t.Init() | |
if err != nil { | |
log.Fatalln("Cannot initialize termui") | |
} | |
// `termui` needs some cleanup when terminating. | |
defer t.Close() | |
// Get the height of the terminal. |
package main | |
// Under normal circumstances, importing two UI libraries at the | |
// same time is probably not a good idea, as each has its own event | |
// loop. This demo code takes care of using only one of these | |
// libraries at a time. | |
import ( | |
"fmt" | |
"log" | |
"os" |
package main | |
// Under normal circumstances, importing two UI libraries at the | |
// same time is probably not a good idea, as each has its own event | |
// loop. This demo code takes care of using only one of these | |
// libraries at a time. | |
import ( | |
"fmt" | |
"log" | |
"os" |
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"syscall" | |
) | |
func main() { |
I hereby claim:
To claim this, I am signing this object: