Skip to content

Instantly share code, notes, and snippets.

@lcaballero
Last active August 29, 2015 14:22
Show Gist options
  • Save lcaballero/f8d89883ab6cd2f9c4fa to your computer and use it in GitHub Desktop.
Save lcaballero/f8d89883ab6cd2f9c4fa to your computer and use it in GitHub Desktop.
Basic tasks in Go... (read file, output json, print to stdout).
package main
import (
"fmt"
"io/ioutil"
"encoding/json"
)
type Data struct {
Id string `json:"id"`
Name string `json:"name"`
Age int32 `json:"age"`
}
func printData() {
d := Data{"guid-1", "superman", 33}
fmt.Println(d)
}
func dataToJson() {
d := Data{"guid-2", "batman", 31}
b,_ := json.Marshal(d)
s := string(b)
fmt.Println(s)
}
func main() {
fmt.Println("Hello, World!")
bytes, _ := ioutil.ReadFile("files/ex-1.txt")
s := string(bytes)
fmt.Println("byte.length %v", len(bytes))
fmt.Println()
fmt.Println(s)
printData()
dataToJson()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment