-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.go
47 lines (42 loc) · 828 Bytes
/
server.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
package dane
import (
"fmt"
"net"
)
//
// Server contains information about a single server: hostname,
// IP address (net.IP) and port number.
//
type Server struct {
Name string
Ipaddr net.IP
Port int
}
//
// NewServer returns an initialized Server structure from given
// name, IP address, and port.
//
func NewServer(name string, ip interface{}, port int) *Server {
s := new(Server)
s.Name = name
switch ip := ip.(type) {
case net.IP:
s.Ipaddr = ip
case string:
s.Ipaddr = net.ParseIP(ip)
}
s.Port = port
return s
}
//
// Address returns an address string for the Server.
//
func (s *Server) Address() string {
return addressString(s.Ipaddr, s.Port)
}
//
// String returns a string representation of Server.
//
func (s *Server) String() string {
return fmt.Sprintf("%s %s", s.Name, s.Address())
}