Permalink
Browse files

Regurgitating JSON stuff now

  • Loading branch information...
ahbishop committed May 6, 2013
1 parent 5593de1 commit c2b7fdb622b431e62c23abc42470db288fb5df59
Showing with 58 additions and 0 deletions.
  1. +58 −0 really_basic.go
View
@@ -5,6 +5,10 @@ import (
"os"
"strings"
"time"
+ "math"
+ "encoding/json"
+ "log"
+ "io"
)
func a_function(data []float32, comm_link chan float32) {
@@ -25,9 +29,21 @@ func thingy(derp, quit chan int) {
case <-quit:
fmt.Println("Die die die")
return
+ default:
+ fmt.Print(" .")
+ time.Sleep(4e8)
}
}
+}
+
+type Weasel struct{
+ Num, Power float64
+}
+var m map[string]Weasel
+var n = map[string]Weasel{
+ "Mr. White" : { -13180123.0124, 109.1813106743},
+ "Mr. Pink" : { -12.0001238513487, 12.139877430},
}
func main() {
@@ -53,4 +69,46 @@ func main() {
quit <- 0
}()
thingy(derp, quit)
+
+
+ m = make(map[string]Weasel)
+
+ m["whut"] = Weasel{
+ 3.14589762, -1.011151304,
+ }
+ delete(m,"whut")
+ delete(m,"nope")
+
+ shrimp_taco := func(x,y float64) float64 {
+ return math.Sqrt(x*x*1.43 + y*3.1+ 0.5*y*y)
+ }
+
+ fmt.Println(shrimp_taco(12.123123862485,3.9876542776))
+
+
+ const da_json = ` {"Type":42, "Text":"Lulzorz"}
+ {"Type":"Gnarly", "Text":"Hang loose"}
+ `
+ type Mail struct{
+ Type, Text string
+ }
+
+ json_decoder := json.NewDecoder(strings.NewReader(da_json))
+ log.Print("Doing some things")
+ for{
+ var m Mail
+ if err:= json_decoder.Decode(&m); err == io.EOF{
+ break
+ }
+ fmt.Printf("I formatted this -> %s: %s\n", m.Type, m.Text)
+
+ input := Mail{ Type: "Sweet", Text:"Narf"}
+ gimp, derr := json.Marshal(input)
+ if derr != nil{
+ fmt.Println("Massive failure:", derr)
+ }
+ os.Stdout.Write(gimp)
+ }
+
+
}

0 comments on commit c2b7fdb

Please sign in to comment.