Skip to content

Instantly share code, notes, and snippets.

@amirhaleem
Created February 27, 2014 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirhaleem/9261839 to your computer and use it in GitHub Desktop.
Save amirhaleem/9261839 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/ugorji/go/codec"
"github.com/drone/routes"
"net/http"
"log"
"io"
"math/rand"
)
var (
r io.Reader
w io.Writer
b []byte
mh = codec.MsgpackHandle{}
)
type Message struct {
AS uint8
A uint8
P []interface{}
}
func Index(w http.ResponseWriter, r *http.Request) {
mh.RawToString = true
pl := []interface{}{}
pl = append(pl, "Sean", "Mike", "Theo", false, rand.Uint32())
t := Message{
AS: 0xAA,
A: 0xAB,
P: pl,
}
enc := codec.NewEncoderBytes(&b, &mh)
if err := enc.Encode(t); err != nil {
log.Print(err)
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE")
w.Header().Add("Access-Control-Allow-Headers", "X-Skynet-SessionToken, Content-Type, X-Requested-With")
w.Write(b)
}
func main() {
mux := routes.New()
mux.Get("/", Index)
http.Handle("/", mux)
log.Print("Listening on 8077...")
http.ListenAndServe("0.0.0.0:8077", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment