github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/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 func (a *UnixAddr) toAddr() Addr { 27 if a == nil { 28 return nil 29 } 30 return a 31 } 32 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) 42 } 43 }