-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
86 lines (74 loc) · 1.92 KB
/
app.go
File metadata and controls
86 lines (74 loc) · 1.92 KB
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
package restify
import (
"fmt"
"github.com/getevo/evo/v2"
"github.com/getevo/evo/v2/lib/application"
"github.com/getevo/evo/v2/lib/db"
"github.com/getevo/evo/v2/lib/db/schema"
"github.com/getevo/postman"
"gorm.io/gorm"
"math"
)
var Prefix = "/admin/rest"
var onReady []func()
var permissionHandler func(permissions Permissions, context *Context) bool
var collection *postman.Collection
type App struct{}
func (app App) Register() error {
if !db.Enabled {
return fmt.Errorf("database is not enabled. restify plugin cannot be registered without a running database. please enable the database in your configuration file")
}
db.OnPrepareContext(func(db *gorm.DB, v interface{}) *gorm.DB {
if context, ok := v.(*Context); ok {
if context.Request.Query("debug").String() == "restify" {
db = db.Debug()
}
if lang := context.Request.Header("language"); lang != "" {
db = db.Set("lang", lang)
} else if lang := context.Request.Cookie("l10n-language"); lang != "" {
db = db.Set("lang", lang)
}
}
return db
})
collection = postman.NewCollection("Restify", "")
if postmanAuthType != "none" {
collection.Auth = &postman.Auth{
Type: postman.AuthType(postmanAuthType),
}
}
return nil
}
func (app App) Router() error {
return nil
}
func (app App) WhenReady() error {
for idx, _ := range schema.Models {
var model = schema.Models[idx]
UseModel(model.Sample)
}
app.registerHooks()
var controller Controller
evo.Get(Prefix+"/models", controller.ModelsHandler)
for _, fn := range onReady {
fn()
}
for idx, _ := range Resources {
for i, _ := range Resources[idx].Actions {
Resources[idx].Actions[i].RegisterRouter()
}
}
if postmanRegistered {
evo.Get(Prefix+"/postman", controller.PostmanHandler)
}
return nil
}
func Ready(fn func()) {
onReady = append(onReady, fn)
}
func (app App) Priority() application.Priority {
return math.MaxInt32
}
func (app App) Name() string {
return "restify"
}