-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
96 lines (87 loc) · 3.35 KB
/
host.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gae
import (
"context"
"errors"
"github.com/bots-go-framework/bots-fw/botsfw"
"github.com/dal-go/dalgo/dal"
"google.golang.org/appengine/v2"
"net/http"
)
// botHost represent information on current hosting platform
type botHost struct {
}
var _ botsfw.BotHost = (*botHost)(nil)
// BotHost returns hosting platform settings & information
func BotHost() botsfw.BotHost {
return botHost{}
}
// Context creates context for http.Request
func (h botHost) Context(r *http.Request) context.Context {
//var appengine
//return r.Context()
var ctx = appengine.NewContext(r)
return ctx
}
// GetHTTPClient creates an HTTP client using AppEngine's URL fetch
func (h botHost) GetHTTPClient(c context.Context) *http.Client {
if c == nil {
panic("c == nil")
}
return http.DefaultClient
//return urlfetch.Client(c)
//return &http.Client{
// Transport: &urlfetch.Transport{
// Context: c,
// },
//}
}
var DbProvider = func(c context.Context) (db dal.DB, err error) {
panic("gae.DbProvider is not set")
//return dalgo2datastore.NewDatabase(c, "")
}
// DB returns database instance
func (h botHost) DB(c context.Context) (db dal.DB, err error) {
if DbProvider == nil {
return nil, errors.New("variable DbProvider is not set in github.com/bots-go-framework/bots-host-gae")
}
return DbProvider(c)
}
// GetBotCoreStores returns bot DAL
//func (h botHost) GetBotCoreStores(platform string, appContext botsfw.BotAppContext, r *http.Request) (stores botsfwdal.DataAccess) {
//
// dbProvider := func(c context.Context) (db dal.Database, err error) {
// return dalgo2datastore.NewDatabase(c, "")
// }
//
// //appUserStore := NewGaeAppUserStore(appContext.AppUserEntityKind(), appContext.AppUserEntityType(), appContext.NewBotAppUserEntity)
// stores.BotAppUserStore = dalgo4botsfw.NewAppUserStore(appContext.AppUserEntityKind(), dbProvider)
//
// switch platform { // TODO: Should not be hardcoded
// case "telegram": // pass
// stores.BotUserStore = dalgo4botsfw.NewBotUserStore("TgUser", dbProvider, func() botsfw.BotUser { return nil }, func(c context.Context, botID string, apiUser botsfw.WebhookActor) (botsfw.BotUser, error) {
// panic("not implemented")
// })
// //if tgChatStore := appContext.GetBotChatEntityFactory(platform); tgChatStore != nil {
// // stores.BotChatStore = NewGaeTelegramChatStore(tgChatStore)
// //} else {
// // stores.BotChatStore = NewGaeTelegramChatStore(func() botsfw.BotChat { return telegram.NewTelegramChatEntity() })
// //}
// //stores.BotUserStore = newGaeTelegramUserStore(appUserStore)
// case "fbm": // pass
// stores.BotUserStore = dalgo4botsfw.NewBotUserStore("FbUser", dbProvider, func() botsfw.BotUser { return nil }, func(c context.Context, botID string, apiUser botsfw.WebhookActor) (botsfw.BotUser, error) {
// panic("not implemented")
// })
// //stores.BotChatStore = NewGaeFbmChatStore()
// //stores.BotUserStore = newGaeFacebookUserStore(appUserStore)
// case "viber": // pass
// stores.BotUserStore = dalgo4botsfw.NewBotUserStore("ViberUser", dbProvider, func() botsfw.BotUser { return nil }, func(c context.Context, botID string, apiUser botsfw.WebhookActor) (botsfw.BotUser, error) {
// panic("not implemented")
// })
// //userChatStore := newGaeViberUserChatStore(appUserStore)
// //stores.BotChatStore = userChatStore
// //stores.BotUserStore = userChatStore
// default:
// panic("Unknown platform: " + platform)
// }
// return
//}