2015-05-18 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgo / go / net / unixsock.go
blob85955845b803d87ad55a20e10af642c062b433ef
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package net
7 // UnixAddr represents the address of a Unix domain socket end point.
8 type UnixAddr struct {
9 Name string
10 Net string
13 // Network returns the address's network name, "unix", "unixgram" or
14 // "unixpacket".
15 func (a *UnixAddr) Network() string {
16 return a.Net
19 func (a *UnixAddr) String() string {
20 if a == nil {
21 return "<nil>"
23 return a.Name
26 func (a *UnixAddr) toAddr() Addr {
27 if a == nil {
28 return nil
30 return a
33 // ResolveUnixAddr parses addr as a Unix domain socket address.
34 // The string net gives the network name, "unix", "unixgram" or
35 // "unixpacket".
36 func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
37 switch net {
38 case "unix", "unixgram", "unixpacket":
39 return &UnixAddr{Name: addr, Net: net}, nil
40 default:
41 return nil, UnknownNetworkError(net)