forked from evolutek/cellaserv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
43 lines (35 loc) · 848 Bytes
/
service.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
package main
import "net"
type Service struct {
Conn net.Conn
Name string
Identification string
Spies []net.Conn
}
type ServiceJSON struct {
Addr string
Name string
Identification string
}
func newService(conn net.Conn, name string, ident string) *Service {
s := &Service{conn, name, ident, nil}
return s
}
func (s *Service) String() string {
if s.Identification != "" {
return s.Name + "/" + s.Identification
}
return s.Name
}
// JSONStruct creates a struc good for JSON encoding.
func (s *Service) JSONStruct() *ServiceJSON {
return &ServiceJSON{
Addr: s.Conn.RemoteAddr().String(),
Name: s.Name,
Identification: s.Identification,
}
}
func (s *Service) sendMessage(msg []byte) {
sendRawMessage(s.Conn, msg)
}
// vim: set nowrap tw=100 noet sw=8: