1
+ // Package backend allows a Go program to import a standard Go package
2
+ // instead of self-hosting the backend API.
3
+ //
4
+ // You need to call the Setup function to initialize all services passing
5
+ // a config.AppConfig. You may create environment variables and load the config
6
+ // directly from confing.LoadConfig.
7
+ //
8
+ // The building blocks of StaticBackend are exported as variable and can be
9
+ // used directly accessing their interface's functions. For instance
10
+ // to use the Volatilizer (cache and pub/sub) you'd use the Cache variable:
11
+ //
12
+ // if err := backend.Cache.Set("key", "value"); err != nil {
13
+ // return err
14
+ // }
15
+ // val, err := backend.Cache.Get("key")
16
+ //
17
+ // The available services are as follow:
18
+ // 1. Cache: caching and pub/sub
19
+ // 2. DB: a raw Persister instance (see below for when to use it)
20
+ // 3. Filestore: raw blob storage
21
+ // 4. Emailer: to send emails
22
+ // 5. Config: the config that was passed to Setup
23
+ // 6. Log: logger
24
+ //
25
+ // You may see those services as raw building blocks to give you the most
26
+ // flexibility. For easy of use, this package wraps important / commonly used
27
+ // functionalities into more developer friendly implementation.
28
+ //
29
+ // For instance, the Membership function wants a model.DatabaseConfig and allow
30
+ // the caller to create account and user as well as reseting password etc.
31
+ //
32
+ // To contrast, all of those can be done from your program by using the DB
33
+ // (Persister) data store, but for convenience this package offers easier /
34
+ // ready-made functions for common use-case.
35
+ //
36
+ // StaticBackend makes your Go web application multi-tenant by default.
37
+ // For this reason you must supply a model.DatabaseConfig and sometimes a
38
+ // model.auth (user performing the actions) to the different parts of the system
39
+ // so the data and security are applied to the right tenant, account and user.
1
40
package backend
2
41
3
42
import (
@@ -150,7 +189,7 @@ func openMongoDatabase(dbHost string) (*mongodrv.Client, error) {
150
189
}
151
190
152
191
if err := cl .Ping (ctx , readpref .Primary ()); err != nil {
153
- return nil , fmt .Errorf ("Ping failed: %v" , err )
192
+ return nil , fmt .Errorf ("ping failed: %v" , err )
154
193
}
155
194
156
195
return cl , nil
@@ -170,20 +209,15 @@ func openPGDatabase(dbHost string) (*sql.DB, error) {
170
209
return dbConn , nil
171
210
}
172
211
173
- // NewID generates a new unique identifier
174
- func NewID () string {
175
- return DB .NewID ()
176
- }
177
-
178
- func findAuth (token string ) model.Auth {
212
+ func findAuthz (token string ) model.Auth {
179
213
auth , err := middleware .ValidateAuthKey (DB , Cache , context .Background (), token )
180
214
if err != nil {
181
215
return model.Auth {}
182
216
}
183
217
return auth
184
218
}
185
219
186
- func findBase (baseID string ) model.DatabaseConfig {
220
+ func findBasez (baseID string ) model.DatabaseConfig {
187
221
var conf model.DatabaseConfig
188
222
if err := Cache .GetTyped (baseID , & conf ); err != nil {
189
223
db , err := DB .FindDatabase (baseID )
0 commit comments