forked from piquette/finance-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
43 lines (32 loc) · 1.06 KB
/
config.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
package server
import (
"net/http"
"time"
"github.com/LandRover/yahoo-finance-mock/utils"
)
const (
// MarketStatePre genius.
MarketStatePre MarketState = "pre"
// MarketStateRegular genius.
MarketStateRegular MarketState = "regular"
// MarketStatePost genius.
MarketStatePost MarketState = "post"
)
// MarketState is a market session.
type MarketState string
// HandleConfigRequest handles an HTTP port directed at the API config stub.
func (s *StubServer) HandleConfigRequest(w http.ResponseWriter, r *http.Request) {
start := time.Now()
validStates := []string{string(MarketStatePre), string(MarketStateRegular), string(MarketStatePost)}
newState := r.PostFormValue("state")
if newState == "" || !utils.Contains(validStates, newState) {
utils.Log(Verbose, "Couldn't parse config url")
s.writeResponse(w, r, start, http.StatusBadRequest, nil)
return
}
// Set market state.
utils.Log(Verbose, "Changed market state from %v to %v", Market, newState)
Market = MarketState(newState)
// Write response.
s.writeResponse(w, r, start, http.StatusOK, nil)
}