-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniform.go
72 lines (56 loc) · 2.59 KB
/
uniform.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
// Copyright 2020 The Uprate Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Reusable microservices communication and standardisation framework
package uniform
import (
"fmt"
"github.com/go-diary/diary"
"time"
)
// A definition of the public functions for a connection interface
type IConn interface {
Request(page diary.IPage, subj string, timeout time.Duration, request Request, scope S) error
Publish(page diary.IPage, subj string, request Request) error
ChainRequest(page diary.IPage, subj string, original IRequest, request Request, scope S) error
ChainPublish(page diary.IPage, subj string, original IRequest, request Request) error
Subscribe(rate time.Duration, subj string, scope S) (ISubscription, error)
QueueSubscribe(rate time.Duration, subj, queue string, scope S) (ISubscription, error)
GeneratePdf(p diary.IPage, timeout time.Duration, serviceId string, html []byte) []byte
SendEmail(p diary.IPage, timeout time.Duration, serviceId, from, fromName, subject, body string, to ...string)
SendEmailX(p diary.IPage, timeout time.Duration, serviceId, from, fromName, subject, body string, attachments []EmailAttachment, to ...string)
SendSms(p diary.IPage, timeout time.Duration, serviceId, body string, to ...string)
SendEmailTemplate(p diary.IPage, timeout time.Duration, asset func(string) []byte, serviceId, from, fromName, path string, vars M, to ...string)
SendEmailTemplateX(p diary.IPage, timeout time.Duration, asset func(string) []byte, serviceId, from, fromName, path string, vars M, attachments []EmailAttachment, to ...string)
SendSmsTemplate(p diary.IPage, timeout time.Duration, asset func(string) []byte, serviceId, path string, vars M, to ...string)
// Populates model with the raw underlying connector which may be required by more advanced users
Raw(model interface{})
Drain() error
Close()
}
// A definition of the public functions for a request interface
type IRequest interface {
Conn() IConn
Read(interface{})
Parameters() P
Context() M
CanReply() bool
Reply(Request) error
ReplyContinue(Request, S) error
Raw() Request
Bytes() []byte
Channel() string
Timeout() time.Duration
StartedAt() time.Time
Remainder() time.Duration
HasError() bool
Error() string
}
// A definition of the public functions for a subscription interface
type ISubscription interface {
Unsubscribe() error
}
// Trigger a panic in a specific format that will tell the api layer to respond with a specific error code
func Alert(code int, message string) {
panic(fmt.Sprintf("alert:%d:%s", code, message))
}