-
Notifications
You must be signed in to change notification settings - Fork 1
/
ambient.go
89 lines (71 loc) · 2.66 KB
/
ambient.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
// Package ambient is a pluggable web app framework.
package ambient
import (
"html/template"
"io"
"net/http"
)
// PluginCore represents the core of any plugin.
type PluginCore interface {
// PluginName should be globally unique. It must start with a lowercase
// letter and then contain only lowercase letters and numbers.
PluginName() string
// PluginVersion must follow https://semver.org/.
PluginVersion() string
}
// Plugin represents a plugin.
type Plugin interface {
PluginCore
// These should all have access to the toolkit.
Enable(*Toolkit) error // optional, called during enable
Disable() error // optional, called during disable
Routes() // optional, called during enable
Assets() ([]Asset, FileSystemReader) // optional, called during enable
Settings() []Setting // optional, called during special operations
GrantRequests() []GrantRequest // optional, called during every plugin operation against data provider
FuncMap() func(r *http.Request) template.FuncMap // optional, called on every render
}
// LoggingPlugin represents a logging plugin.
type LoggingPlugin interface {
PluginCore
Logger(appName string, appVersion string, writer io.Writer) (AppLogger, error)
}
// StoragePluginGroup represents a storage plugin and an optional encryption
// package.
type StoragePluginGroup struct {
Storage StoragePlugin
Encryption StorageEncryption
}
// StoragePlugin represents a storage plugin.
type StoragePlugin interface {
PluginCore
Storage(logger Logger) (DataStorer, SessionStorer, error)
}
// StorageEncryption represents a encryption/decryption for a storage
// plugin.
type StorageEncryption interface {
Encrypt(data []byte) ([]byte, error)
Decrypt(enc []byte) ([]byte, error)
}
// RouterPlugin represents a router engine plugin.
type RouterPlugin interface {
PluginCore
Router(logger Logger, render Renderer) (AppRouter, error)
}
// TemplateEnginePlugin represents a template engine plugin.
type TemplateEnginePlugin interface {
PluginCore
TemplateEngine(logger Logger, injector AssetInjector) (Renderer, error)
}
// SessionManagerPlugin represents a session manager plugin.
type SessionManagerPlugin interface {
PluginCore
// Session manager should have middleware with it.
SessionManager(logger Logger, sessionStorer SessionStorer) (AppSession, error)
Middleware() []func(next http.Handler) http.Handler
}
// MiddlewarePlugin represents a middleware plugin.
type MiddlewarePlugin interface {
Plugin
Middleware() []func(next http.Handler) http.Handler // optional, called during enable
}