-
Notifications
You must be signed in to change notification settings - Fork 187
/
app.go
86 lines (71 loc) · 1.54 KB
/
app.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
package application
import (
"encoding/json"
"errors"
"fmt"
"reflect"
http_service "github.com/eolinker/eosc/eocontext/http-context"
"github.com/eolinker/eosc/utils/config"
)
var (
appSkill string
ErrTokenNotFound = errors.New("token not found")
ErrInvalidToken = errors.New("invalid token")
ErrTokenExpired = errors.New("token is expired")
)
func init() {
var t IApp
appSkill = config.TypeNameOf(&t)
}
type IApp interface {
Id() string
Name() string
Labels() map[string]string
Disable() bool
IAppExecutor
}
type IAppExecutor interface {
Execute(ctx http_service.IHttpContext) error
}
func CheckSkill(skill string) bool {
return skill == appSkill
}
type IAuth interface {
ID() string
Check(appID string, users []ITransformConfig) error
Set(app IApp, users []ITransformConfig)
Del(appID string)
UserCount() int
IAuthUser
}
type IAuthUser interface {
Driver() string
GetUser(ctx http_service.IHttpContext) (*UserInfo, bool)
}
type ITransformConfig interface {
Config() interface{}
SetType(typ reflect.Type) error
}
type BaseConfig struct {
data []byte
v interface{}
}
func (a *BaseConfig) SetType(typ reflect.Type) error {
v := reflect.New(typ.Elem()).Interface()
err := json.Unmarshal(a.data, v)
if err != nil {
return fmt.Errorf("set type error: %v", err)
}
a.v = v
return nil
}
func (a *BaseConfig) Config() interface{} {
return a.v
}
func (a *BaseConfig) UnmarshalJSON(bytes []byte) error {
a.data = bytes
return nil
}
func (a *BaseConfig) MarshalJSON() ([]byte, error) {
return json.Marshal(a.v)
}