-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathketty.go
106 lines (93 loc) · 2.29 KB
/
ketty.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
95
96
97
98
99
100
101
102
103
104
105
package ketty
import (
U "github.com/yyzybb537/ketty/url"
P "github.com/yyzybb537/ketty/protocol"
B "github.com/yyzybb537/ketty/balancer"
A "github.com/yyzybb537/ketty/aop"
_ "github.com/yyzybb537/ketty/protocol/grpc"
_ "github.com/yyzybb537/ketty/protocol/http"
)
type Dummy interface{}
type Client P.Client
type Server P.Server
// @目前支持的组件
//1.Protocol
// grpc, http, https
//2.Balancer
// robin
//3.Driver for find service
// etcd
//4.AOP
// cost, exception, logger, trace
// @后续计划
//1.Protocol
// none
//2.Balancer
// conhash, random
//3.Driver for find service
// zookeeper
//* Driver mode:
// only-master, master-groups
//4.AOP
// timeout, trace-timeout, statistics
//5.Log
// glog or seelog
// @sUrl: protocol://ip[:port][,ip[:port]]/path
// E.g:
// http://127.0.0.1:8030/path
// https://127.0.0.1:8030
// grpc://127.0.0.1:8030,127.0.0.1:8031
//
// Support marshal: pb(default), json.
// Support http method: GET, POST(default)
// Support http data transport: body(default), query, multipart
//
// User can make extend marshal.
// If use `query`, the marshal will be ignored.
//
// Others E.g:
// http.json://127.0.0.1:8030/path
// http.json.query://127.0.0.1:8030/path
// http.pb.query://127.0.0.1:8030/path
// http.json.get.query://127.0.0.1:8030/path
// http.json.post.multipart://127.0.0.1:8030/path
// http.get.query://127.0.0.1:8030/path
// http.post.body://127.0.0.1:8030/path
//
// @sBalanceUrl: driver://ip[:port][,ip[:port]]/path
// etcd://127.0.0.1:2379/path
func Listen(sUrl, sDriverUrl string) (server Server, err error) {
url, err := U.UrlFromString(sUrl)
if err != nil {
return
}
driverUrl, err := U.UrlFromString(sDriverUrl)
if err != nil {
return
}
proto, err := P.GetProtocol(url.GetMainProtocol())
if err != nil {
return
}
server, err = proto.CreateServer(url, driverUrl)
server.AddAop(A.DefaultAop().GetAop()...)
return
}
func Dial(sUrl, sBalancer string) (client Client, err error) {
url, err := U.UrlFromString(sUrl)
if err != nil {
return
}
balancer, err := B.GetBalancer(sBalancer)
if err != nil {
return
}
clients := newClients(url, balancer, nil)
err = clients.dial()
if err != nil {
return
}
client = clients
client.AddAop(A.DefaultAop().GetAop()...)
return
}