-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (51 loc) · 1.69 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"net/http"
"strings"
"time"
"trading-rules/constants"
"trading-rules/redis"
"trading-rules/service"
"trading-rules/utils"
log "github.com/sirupsen/logrus"
)
func init() {
redis.InitRedisConnection()
}
func main() {
handler := http.NewServeMux()
handler.HandleFunc(constants.ControllerMapping, TradingRules)
http.ListenAndServe(constants.DeployedPath, handler)
}
// TradingRules : Controller to initiate data load operation
func TradingRules(w http.ResponseWriter, r *http.Request) {
log.Info("Starting data load")
// Parse input files into bytes
fileInputByte, err := utils.FileReader(r)
if err != nil {
log.Error(err)
return
}
ProcessLoadedFile(w, fileInputByte)
}
// ProcessLoadedFile : Process input data file
func ProcessLoadedFile(w http.ResponseWriter, fileInputByte []byte) bool {
processFileLoad := false
customerInputInfo := strings.Split(string(fileInputByte), "\n")
// Clear any Redis keys from previous data loads
service.ClearPreviousLoadAttempt(customerInputInfo)
// Sleep time for two seconds between Delete operation and Get/Set operations
time.Sleep(2000)
// Start loading data into redis while performing calculations
service.DataLoadSequence(w, customerInputInfo)
SetResponseHeaders(&w)
log.Info("Data load completed")
processFileLoad = true
return processFileLoad
}
// SetResponseHeaders : Set the required standard response headers
func SetResponseHeaders(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
(*w).Header().Set("Access-Control-Allow-Methods", "POST")
(*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
}