Last active
July 16, 2021 14:12
-
-
Save kirk91/7569d02256566b0179963a35a63f92eb to your computer and use it in GitHub Desktop.
Http over unix domain socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"net/http" | |
"os" | |
) | |
func main() { | |
udsPath := "/tmp/http-unix.sock" | |
os.Remove(udsPath) //nolint:errcheck | |
lis, err := net.Listen("unix", udsPath) | |
if err != nil { | |
panic(err) | |
} | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello, world!") | |
}) | |
http.Serve(lis, nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment