-
Notifications
You must be signed in to change notification settings - Fork 35
/
api.go
94 lines (73 loc) · 2.14 KB
/
api.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
package endly
import (
"github.com/viant/toolbox"
"github.com/viant/toolbox/data"
"sync"
)
// AppName represents endly application name
const AppName = "endly"
// Namespace represents endly namespace
const Namespace = "github.com/viant/endly/"
// Manager represents a endly service manager
type Manager interface {
//Name returns an application SessionID
Name() string
//Version returns an application version
Version() string
//Service return a workflow service for provided SessionID, request, or error
Service(input interface{}) (Service, error)
//Register register service in this manager
Register(service Service)
//NewContext returns new workflow context.
NewContext(context toolbox.Context) *Context
//Run run requests
Run(context *Context, request interface{}) (interface{}, error)
}
// Service represents an endly service
type Service interface {
//service id
ID() string
//service state map
State() data.Map
//Run service action for supported request types.
Run(context *Context, request interface{}) *ServiceResponse
//Route returns service action route
Route(action string) (*Route, error)
Mutex() *sync.RWMutex
Actions() []string
}
// Validator represents generic validator
type Validator interface {
Validate() error
}
// Initializer represents generic initializer
type Initializer interface {
Init() error
}
// ServiceResponse service response
type ServiceResponse struct {
Status string
Error string
Response interface{}
Err error
}
// Route represents service action route
type Route struct {
Action string
RequestInfo *ActionInfo
ResponseInfo *ActionInfo
RequestProvider func() interface{}
ResponseProvider func() interface{}
Handler func(context *Context, request interface{}) (interface{}, error)
OnRawRequest func(context *Context, rawRequest map[string]interface{}) error //when specified it is called each time action literal is used when match
}
// Description represents example use case
type UseCase struct {
Description string
Data string
}
// ActionInfo represent an action info
type ActionInfo struct {
Description string
Examples []*UseCase
}