go-dvote/net/net.go
net/net.goRaw
1package net
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7 "time"
8 "strconv"
9 "io"
10)
11
12type submission struct {
13 Type string
14 Nonce []byte
15 Key []byte
16 Package []byte
17 Expiry time.Time
18}
19
20func parseSubmission(rw http.ResponseWriter, request *http.Request) {
21 decoder := json.NewDecoder(request.Body)
22
23 var s submission
24 err := decoder.Decode(&s)
25
26 if err != nil {
27 panic(err)
28 }
29
30 //check PoW
31 //check discriminator
32 //decrypt
33 //check franchise
34 //add to leveldb
35 j, err := json.Marshal(s)
36 //io.WriteString(rw, string(j))
37}
38
39func listen(port int) {
40 http.HandleFunc("/submit", parseSubmission)
41 portstr := strconv.Itoa(port)
42 go func() {
43 fmt.Println("serving on " + portstr)
44 err := http.ListenAndServe(":" + portstr, nil)
45 if err != nil {
46 panic("ListenAndServe: " + err.Error())
47 }
48 }()
49}