-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
33 lines (25 loc) · 850 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/inithost/", handleInitHost)
http.HandleFunc("/connect/", handleConnectPeer)
fmt.Println("Server listening on port 8080...")
http.ListenAndServe(":8080", nil)
// go connectToPeer("12D3KooWHeAvNK221WW7heHbrv6sgQf1FoPmucN2gbFTkCd2nt8T")
// go connectToPeer("12D3KooWQFeTgsRRyRqeLGVNC76HTpvyJTZKvNSQEnBbxiLNqNGT")
}
func handleInitHost(w http.ResponseWriter, r *http.Request) {
response := initHost("bvvinai", "bvvinai@1357")
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
func handleConnectPeer(w http.ResponseWriter, r *http.Request) {
peerid := r.URL.Query().Get("peerid")
response := connectToPeer(peerid)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}