blockchainIDsystem/serverCA/restRoutes.go
serverCA/restRoutes.goRaw
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7)
8
9type Routes []Route
10
11var routes = Routes{
12 Route{
13 "Index",
14 "GET",
15 "/",
16 Index,
17 },
18 Route{
19 "GetPeers",
20 "GET",
21 "/peers",
22 GetPeers,
23 },
24 Route{
25 "GetBlockchain",
26 "GET",
27 "/blockchain",
28 GetBlockchain,
29 },
30}
31
32type Address struct {
33 Address string `json:"address"` //the pubK of the user, to perform logins
34}
35
36func Index(w http.ResponseWriter, r *http.Request) {
37 fmt.Fprintln(w, "CA")
38}
39func GetPeers(w http.ResponseWriter, r *http.Request) {
40 getPeers()
41
42 jResp, err := json.Marshal(peersList)
43 check(err)
44 fmt.Fprintln(w, string(jResp))
45}
46
47func GetBlockchain(w http.ResponseWriter, r *http.Request) {
48 fmt.Print("aaaaa: ")
49 fmt.Println(blockchain.Blocks[len(blockchain.Blocks)-1].Hash)
50 reconstructBlockchainFromBlock("http://"+config.IP+":"+config.ServerRESTPort, blockchain.Blocks[len(blockchain.Blocks)-1].Hash)
51
52 jResp, err := json.Marshal(blockchain)
53 check(err)
54 fmt.Fprintln(w, string(jResp))
55}