-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (53 loc) · 1.62 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
package main
/* SELF NOTE go mod init, go build, go mod tidy, go mod vendor - GO Modules project initialization*/
import (
"math/rand"
"os"
"time"
"log"
"strconv"
"os/signal"
"github.com/siddhant94/BidderService/config"
"github.com/siddhant94/BidderService/models"
"github.com/siddhant94/BidderService/utils"
)
var defaultBidders int
func init() {
rand.Seed(time.Now().UnixNano()) // Initialize application wide Seed for rand
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
func main() {
// Bidder Service params - delay-time, portToBind, URL (to register itself with auctioneer)
// 1) Number of bidders and rest system generated. (JSON, YAML etc) config file, if user-input support for all three.
var (
numOfBidders int
err error
)
if len(os.Args) > 1 {
numOfBidders, err = strconv.Atoi(os.Args[1])
if err != nil {
log.Println("Unable to convert argument as int. Picking up default value from config.")
}
}
if numOfBidders == 0 { // Since zero value of int is 0
numOfBidders, err = strconv.Atoi(config.GetAppConfig().DefaultBidders)
if err != nil {
log.Println("Error: string to int for default value in config. Unable to proceed")
return
}
}
var bidderList []*models.Bidder
bidderList = make([]*models.Bidder, numOfBidders)
log.Println(numOfBidders)
bidderList = utils.Map(bidderList, utils.PopulateBidder)
utils.BidderService(bidderList)
log.Println("Bidder servers up.")
// We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C)
// SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
select {
case <-c:
break
}
}