-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockInfo.go
44 lines (37 loc) · 1.14 KB
/
stockInfo.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
package handlers
import (
"net/http"
"github.com/fercevik729/STLKER/octopus/data"
"github.com/gorilla/mux"
)
func (c *ControlHandler) GetInfo(w http.ResponseWriter, r *http.Request) {
// Retrieve URI variables
vars := mux.Vars(r)
ticker := vars["ticker"]
destCurr := vars["currency"]
// Get the stock information
stock, err := Info(ticker, destCurr, c.client)
if err != nil {
c.l.Println("[ERROR] Couldn't get ticker information, ensure ticker and destination currency are valid")
w.WriteHeader(http.StatusBadRequest)
}
// Write the data to the client
w.Header().Set("Content-Type", "application/json")
c.setStockCache(r, &stock)
data.ToJSON(stock, w)
}
func (c *ControlHandler) MoreInfo(w http.ResponseWriter, r *http.Request) {
// Retrieve URI variable
vars := mux.Vars(r)
ticker := vars["ticker"]
// Get the company overview
co, err := CompanyOverview(ticker, c.client)
if err != nil {
c.l.Println("[ERROR] Couldn't get company overview information for ticker:", ticker, "err:", err)
w.WriteHeader(http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
c.setStockCache(r, &co)
data.ToJSON(co, w)
}