-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
- [ x] I have looked at the documentation here first?
- [ x] I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
v10.23.0
Issue, Question or Enhancement:
The unix_addr check is useless. I looked into the src:
func isUnixAddrResolvable(fl FieldLevel) bool {
_, err := net.ResolveUnixAddr("unix", fl.Field().String())
return err == nil
}and in stdlib net:
https://cs.opensource.google/go/go/+/refs/tags/go1.23.4:src/net/unixsock.go;l=57
func ResolveUnixAddr(network, address string) (*UnixAddr, error) {
switch network {
case "unix", "unixgram", "unixpacket":
return &UnixAddr{Name: address, Net: network}, nil
default:
return nil, UnknownNetworkError(network)
}
}effectively this will never throw an error, since you're always passing "unix".
In fact, ResolveUnixAddr is itself useless to check if the socket actually exists.
You need something that checks if the file exists and if that file is a socket:
func IsSocket(filePath string) (err error) {
stats, err := os.Stat(filePath)
if err != nil {
err = fmt.Errorf("check file existence: %w", err)
return
}
if stats.Mode().Type() != fs.ModeSocket {
err = fmt.Errorf("not socket file: %v", filePath)
return
}
return
}