1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Further consolidate the libraries

This commit is contained in:
Asim Aslam
2019-06-03 18:44:43 +01:00
parent fe060b2d0b
commit b42b6fa0fc
110 changed files with 11934 additions and 83 deletions

30
api/handler/unix/unix.go Normal file
View File

@ -0,0 +1,30 @@
// Package unix reads from a unix socket expecting it to be in /tmp/path
package unix
import (
"fmt"
"io"
"net"
"net/http"
"path/filepath"
)
type Handler struct{}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sock := fmt.Sprintf("%s.sock", filepath.Clean(r.URL.Path))
path := filepath.Join("/tmp", sock)
c, err := net.Dial("unix", path)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
go io.Copy(c, r.Body)
// write response
io.Copy(w, c)
}
func (h *Handler) String() string {
return "unix"
}