parent
fb698301e4
commit
53c9620b8a
|
@ -5,6 +5,8 @@ import "log"
|
||||||
import "net/http"
|
import "net/http"
|
||||||
import "io/ioutil"
|
import "io/ioutil"
|
||||||
import "strings"
|
import "strings"
|
||||||
|
import "os"
|
||||||
|
import "time"
|
||||||
|
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
@ -37,6 +39,12 @@ func main() {
|
||||||
http.ListenAndServe(":9000", nil)
|
http.ListenAndServe(":9000", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeToFile(filename string, a string) {
|
||||||
|
f, _ := os.Create(filename)
|
||||||
|
f.WriteString(a)
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func handler2(w http.ResponseWriter, r *http.Request) {
|
func handler2(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
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-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||||
|
@ -50,8 +58,19 @@ func handler2(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println("body =", j)
|
log.Println("body =", j)
|
||||||
log.Println("err =", err)
|
log.Println("err =", err)
|
||||||
|
|
||||||
|
// change the JSON int a protobuf
|
||||||
account := JSONtoPB(string(body))
|
account := JSONtoPB(string(body))
|
||||||
account.Token = "testing a token"
|
account.Token = "testing a token"
|
||||||
|
|
||||||
log.Println("account =", account)
|
log.Println("account =", account)
|
||||||
|
|
||||||
|
// change it back to JSON
|
||||||
|
marshaler := &jsonpb.Marshaler{}
|
||||||
|
stuff, _ := marshaler.MarshalToString(&account)
|
||||||
|
log.Println(stuff)
|
||||||
|
|
||||||
|
current := time.Now()
|
||||||
|
filename := "/tmp/" + current.Format("2006-01-02-15-04-05")
|
||||||
|
log.Println("filename =", filename)
|
||||||
|
// write to file
|
||||||
|
writeToFile(filename, stuff + "\n")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue