/
duplicate.go
65 lines (45 loc) · 1.43 KB
/
duplicate.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
/* Copyright (C) Karolis Rusenas - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Karolis Rusenas <karolis.rusenas@gmail.com>, February 2016
*/
package duplicate
import (
log "github.com/Sirupsen/logrus"
hv "github.com/SpectoLabs/hoverfly"
"net/http"
"fmt"
)
type MasterConfiguration struct {
hvCfg *hv.Configuration
hvDBClient *hv.DBClient
}
func Start(mode, databasePath string) {
log.SetFormatter(&log.TextFormatter{})
log.Info("--------Hoverfly mobile is starting!!-------")
log.SetFormatter(&log.JSONFormatter{})
cfg := hv.InitSettings()
// overriding default settings
cfg.Mode = mode
// overriding destination
cfg.Destination = "."
//cfg.DatabaseName = "/data/data/dev.client.android/databases/clientDB.db"
cfg.DatabaseName = fmt.Sprintf("%s/requests.db", databasePath)
proxy, dbClient := hv.GetNewHoverfly(cfg)
//mc := &MasterConfiguration{
// hvCfg: cfg,
// hvDBClient: dbClient,
//}
defer dbClient.Cache.DS.Close()
// starting admin interface
dbClient.StartAdminInterface()
log.Info("Admin interface started")
// start metrics registry flush
dbClient.Counter.Init()
log.Info("Metrics counter started")
log.Info("Starting main proxy...")
log.Warn(http.ListenAndServe(fmt.Sprintf(":%s", cfg.ProxyPort), proxy))
}
func Greet(mode string) string {
return fmt.Sprintf("Hoverfly ready, %s mode!", mode)
}