this is really a more basic go idiom question but this serves as a good example. (BTW 100% go newb)
Trying to listen to unix socket and process messages. Stolen code from various places but I cant 'cast' things right
package main
import "fmt"
import "net"
func main(){
ln,err := net.Listen("unix", "/var/service/daemon2")
if err!= nil {
fmt.Println(err)
return
}
for {
c, err := ln.Accept()
if err != nil {
fmt.Println(err)
continue
}
// handle the connection
go handleServerConnection(c)
}
}
func handleServerConnection(c net.UnixConn) {
// receive the message
buff := make([]byte, 1024)
oob := make([]byte, 1024)
_,_,_,_,err:=c.ReadMsgUnix(buff,oob);
if err != nil {
fmt.Println(err)
}
}
I need 'c' inside handleServerConnection to be of type UNixConn so that I can call ReadUNixMsg. But the generic Listen code makes a generic Conn object. So this code doesnt compile.
I tried various convert / cast type things UnixConn(c) for example but all to no avail.