-
Notifications
You must be signed in to change notification settings - Fork 2
/
winners.go
56 lines (43 loc) · 1.28 KB
/
winners.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package api
import (
"log"
"net/http"
"github.com/archway-network/valuter/configs"
"github.com/archway-network/valuter/tasks"
"github.com/archway-network/valuter/tools"
routing "github.com/julienschmidt/httprouter"
)
/*----------------------*/
/*
* This function implements GET /winners
*/
func GetWinners(resp http.ResponseWriter, req *http.Request, params routing.Params) {
winnersList, err := tasks.GetAllWinners()
if err != nil {
log.Printf("Error in db query: %v", err)
http.Error(resp, "Internal Server Error: "+err.Error(), http.StatusInternalServerError)
return
}
tools.SendJSON(resp, winnersList.GetItems())
}
/*-------------*/
/*
* This function implements GET /winners/:address
*/
func GetWinner(resp http.ResponseWriter, req *http.Request, params routing.Params) {
address := params.ByName("address")
winnerResults, err := tasks.GetWinnerByAddress(address)
if err != nil {
log.Printf("Error in db query: %v", err)
http.Error(resp, "Internal Server Error: "+err.Error(), http.StatusInternalServerError)
return
}
tools.SendJSON(resp, winnerResults)
}
/*-------------*/
/*
* This function implements GET /challenges
*/
func GetListOfChallenges(resp http.ResponseWriter, req *http.Request, params routing.Params) {
tools.SendJSON(resp, configs.Configs.Tasks)
}