mirror of
https://github.com/openfaas/faas.git
synced 2025-06-16 21:06:54 +00:00
gateway 0.01
This commit is contained in:
parent
606a50e124
commit
734c8a3dc6
1
gateway/.gitignore
vendored
Normal file
1
gateway/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
gateway
|
15
gateway/Dockerfile
Normal file
15
gateway/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from golang:1.7.3
|
||||||
|
|
||||||
|
RUN go get -d github.com/docker/docker/api/types \
|
||||||
|
&& go get -d github.com/docker/docker/api/types/filters \
|
||||||
|
&& go get -d github.com/docker/docker/api/types/swarm \
|
||||||
|
&& go get -d github.com/docker/docker/client
|
||||||
|
|
||||||
|
WORKDIR /go/src/app/
|
||||||
|
RUN go get github.com/gorilla/mux
|
||||||
|
COPY server.go .
|
||||||
|
RUN go build
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD ["./app"]
|
||||||
|
|
40
gateway/server.go
Normal file
40
gateway/server.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
)
|
||||||
|
|
||||||
|
func proxy(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "POST" {
|
||||||
|
log.Println(r.Header)
|
||||||
|
header := r.Header["X-Function"]
|
||||||
|
log.Println(header)
|
||||||
|
if header[0] == "catservice" {
|
||||||
|
// client := http.Client{Timeout: time.Second * 2}
|
||||||
|
requestBody, _ := ioutil.ReadAll(r.Body)
|
||||||
|
buf := bytes.NewBuffer(requestBody)
|
||||||
|
|
||||||
|
response, err := http.Post("http://"+header[0]+":"+strconv.Itoa(8080)+"/", "text/plain", buf)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
responseBody, _ := ioutil.ReadAll(response.Body)
|
||||||
|
w.Write(responseBody)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
r := mux.NewRouter()
|
||||||
|
r.HandleFunc("/", proxy)
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", r))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user