58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
import "log"
|
|
import "net/http"
|
|
import "io/ioutil"
|
|
import "strings"
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
import "github.com/golang/protobuf/jsonpb"
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
func handler(w http.ResponseWriter, r *http.Request) {
|
|
// spew.Dump(r)
|
|
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
|
|
log.Printf("handler: fucking unknown path")
|
|
}
|
|
|
|
func JSONtoPB(a string) pb.Account {
|
|
sets := pb.Account{}
|
|
|
|
err := jsonpb.Unmarshal(strings.NewReader(string(a)), &sets)
|
|
if err != nil {
|
|
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
|
}
|
|
spew.Dump(sets)
|
|
return sets
|
|
}
|
|
|
|
func main() {
|
|
log.Println("listen on :9000")
|
|
|
|
http.HandleFunc("/", handler)
|
|
http.HandleFunc("/email", handler2)
|
|
|
|
http.ListenAndServe(":9000", nil)
|
|
}
|
|
|
|
func handler2(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
|
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
|
|
|
|
// spew.Dump(r)
|
|
fmt.Fprintf(w, "Hi there, handler2 %s!", r.URL.Path[1:])
|
|
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
j := string(body)
|
|
log.Println("body =", j)
|
|
log.Println("err =", err)
|
|
|
|
account := JSONtoPB(string(body))
|
|
account.Token = "testing a token"
|
|
|
|
log.Println("account =", account)
|
|
}
|