Last active
August 29, 2015 14:22
-
-
Save lcaballero/f8d89883ab6cd2f9c4fa to your computer and use it in GitHub Desktop.
Basic tasks in Go... (read file, output json, print to stdout).
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" | |
"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