-
Notifications
You must be signed in to change notification settings - Fork 0
/
het_rpc_client_session.go
67 lines (57 loc) · 1.24 KB
/
het_rpc_client_session.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
package main
import (
"fmt"
"log"
"net/rpc"
)
type Session struct {
Login string
Useragent string
}
type SessionID struct {
ID string
}
type SessionManagerI interface {
Create(*Session) (*SessionID, error)
Check(*SessionID) *Session
Delete(*SessionID)
}
// N.B. adapter implements interface as thin wrapper
type SessionManager struct {
client *rpc.Client
}
// factory
func NewSessManager() *SessionManager {
client, err := rpc.DialHTTP("tcp", "localhost:8081")
if err != nil {
log.Fatal("dialing:", err)
}
return &SessionManager{
client: client,
}
}
func (sm *SessionManager) Create(in *Session) (*SessionID, error) {
id := new(SessionID)
err := sm.client.Call("SessionManager.Create", in, id)
if err != nil {
fmt.Println("SessionManager.Create error:", err)
return nil, nil
}
return id, nil
}
func (sm *SessionManager) Check(in *SessionID) *Session {
sess := new(Session)
err := sm.client.Call("SessionManager.Check", in, sess)
if err != nil {
fmt.Println("SessionManager.Check error:", err)
return nil
}
return sess
}
func (sm *SessionManager) Delete(in *SessionID) {
var reply int
err := sm.client.Call("SessionManager.Delete", in, &reply)
if err != nil {
fmt.Println("SessionManager.Delete error:", err)
}
}