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
#!/usr/bin/env bash | |
# This script runs all steps from the article. | |
# | |
# If the folder "graphite-demo" exists, | |
# it trashes this folder and deletes the repo on GitHub. | |
MMDD=$(date "+%m-%d") | |
# cleanup |
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
# This script trashes the current local repo | |
# and recreates all steps from the article. | |
# | |
# Start in the parent dir of the cloned repo "graphite-demo". | |
# Ensure the repo is deleted on GitHub (via the browser as I gave gh no delete rights.) | |
trash graphite-demo | |
# gh repo delete christophberger-articles/graphite-demo # if gh delete is activated | |
gh repo create christophberger-articles/graphite-demo --private --clone |
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" | |
"time" | |
) | |
func main() { | |
c := make(chan int) |
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" | |
) | |
func main() { | |
x := make([]int, 1, 10) | |
var a []int |
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
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: | |
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
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" { |
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
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. |
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
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. |
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 | |
// 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" |
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 | |
// 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" |
NewerOlder