Skip to content

Instantly share code, notes, and snippets.

@Burning-Chai
Created September 12, 2015 07:54
Show Gist options
  • Save Burning-Chai/20cd719e9986aadd23e1 to your computer and use it in GitHub Desktop.
Save Burning-Chai/20cd719e9986aadd23e1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"encoding/json"
)
type Student struct {
Id int
Name string
Class string
}
func main() {
fmt.Println("Server running!!!")
http.HandleFunc("/hello", helloHandler)
}
func helloHandler(rw http.ResponseWriter, req *http.Request) {
students := []Student{
{Id:1, Name:"Yanou", Class:"1A"},
{Id:2, Name:"Tanaka", Class:"1B"},
}
data, _ := json.Marshal(students)
rw.Write(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment