Home | History | Annotate | Download | only in net
      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.
      4 
      5 package net
      6 
      7 // UnixAddr represents the address of a Unix domain socket end point.
      8 type UnixAddr struct {
      9 	Name string
     10 	Net  string
     11 }
     12 
     13 // Network returns the address's network name, "unix", "unixgram" or
     14 // "unixpacket".
     15 func (a *UnixAddr) Network() string {
     16 	return a.Net
     17 }
     18 
     19 func (a *UnixAddr) String() string {
     20 	if a == nil {
     21 		return "<nil>"
     22 	}
     23 	return a.Name
     24 }
     25 
     26 func (a *UnixAddr) isWildcard() bool {
     27 	return a == nil || a.Name == ""
     28 }
     29 
     30 func (a *UnixAddr) opAddr() Addr {
     31 	if a == nil {
     32 		return nil
     33 	}
     34 	return a
     35 }
     36 
     37 // ResolveUnixAddr parses addr as a Unix domain socket address.
     38 // The string net gives the network name, "unix", "unixgram" or
     39 // "unixpacket".
     40 func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
     41 	switch net {
     42 	case "unix", "unixgram", "unixpacket":
     43 		return &UnixAddr{Name: addr, Net: net}, nil
     44 	default:
     45 		return nil, UnknownNetworkError(net)
     46 	}
     47 }
     48