rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/net/unixsock.go (about) 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 // ResolveUnixAddr parses addr as a Unix domain socket address. 27 // The string net gives the network name, "unix", "unixgram" or 28 // "unixpacket". 29 func ResolveUnixAddr(net, addr string) (*UnixAddr, error) { 30 switch net { 31 case "unix", "unixgram", "unixpacket": 32 return &UnixAddr{Name: addr, Net: net}, nil 33 default: 34 return nil, UnknownNetworkError(net) 35 } 36 }