forked from go-catupiry/catu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolo.go
61 lines (46 loc) · 1.22 KB
/
bolo.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
package bolo
import (
"net/http"
"net/http/httptest"
"os"
"github.com/go-bolo/bolo/configuration"
"github.com/joho/godotenv"
"gorm.io/gorm"
)
// TODO! remove that global app:
var appInstance App
func init() {
initDotEnvConfigSupport()
}
func Init(options *AppOptions) App {
appInstance = NewApp(options)
InitSanitizer()
return appInstance
}
// Init doc env config with default development.env configuration file
// The configuration file pattern is: [environment].env
func initDotEnvConfigSupport() {
env, _ := os.LookupEnv("GO_ENV")
if env == "" {
env = "development"
}
if _, err := os.Stat(env + ".env"); err == nil {
godotenv.Load(env + ".env")
}
}
func GetApp() App {
return appInstance
}
func GetConfiguration() configuration.ConfigurationInterface {
return appInstance.GetConfiguration()
}
func GetDefaultDatabaseConnection() *gorm.DB {
return appInstance.GetDB()
}
// NewBotContext - Create a new request context for non http calls and testing
func NewBotContext(app App) (*RequestContext, error) {
req, _ := http.NewRequest(http.MethodGet, "/", nil)
res := httptest.NewRecorder()
c := app.GetRouter().NewContext(req, res)
return NewRequestContext(&RequestContextOpts{App: app, EchoContext: c}), nil
}