1
0
mirror of https://github.com/golang/go synced 2024-10-05 10:31:22 -06:00
go/src/pkg/net/unixsock.go
Mikio Hara 8b6d501704 net: fix documentation for UnixAddr
Also simplifies ResolveUnixAddr.

R=golang-dev, dave, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/7510047
2013-03-23 07:39:43 +09:00

46 lines
1023 B
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Unix domain sockets
package net
// UnixAddr represents the address of a Unix domain socket end point.
type UnixAddr struct {
Name string
Net string
}
// Network returns the address's network name, "unix", "unixgram" or
// "unixpacket".
func (a *UnixAddr) Network() string {
return a.Net
}
func (a *UnixAddr) String() string {
if a == nil {
return "<nil>"
}
return a.Name
}
func (a *UnixAddr) toAddr() Addr {
if a == nil { // nil *UnixAddr
return nil // nil interface
}
return a
}
// ResolveUnixAddr parses addr as a Unix domain socket address.
// The string net gives the network name, "unix", "unixgram" or
// "unixpacket".
func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
switch net {
case "unix", "unixgram", "unixpacket":
return &UnixAddr{Name: addr, Net: net}, nil
default:
return nil, UnknownNetworkError(net)
}
}