1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| package main
import ( "fmt" "net" "net/http" "os" "syscall" "time" )
func main() { addr, _ := net.ResolveUnixAddr("unix", "/dev/shm/migrate.sock") unixLn, _ := net.ListenUnix("unix", addr) conn, _ := unixLn.AcceptUnix() buf := make([]byte, 32) oob := make([]byte, 32) time.Sleep(5 * time.Second) _, oobn, _, _, _ := conn.ReadMsgUnix(buf, oob) scms, _ := syscall.ParseSocketControlMessage(oob[:oobn]) if len(scms) > 0 { fds, _ := syscall.ParseUnixRights(&scms[0]) f := os.NewFile(uintptr(fds[0]), "") ln, _ := net.FileListener(f) tcpLn, _ := ln.(*net.TCPListener) http.Serve(tcpLn, &MyHttp{}) } }
type MyHttp struct { }
func (*MyHttp) ServeHTTP(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "hello world") }
|