Skip to content

Commit

Permalink
Add proxy layer
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrodzicki committed Apr 20, 2020
1 parent fe0d1c1 commit 6673a1f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/unifi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"bytes"
"flag"
"io/ioutil"
"log"
"net/http"
)

var (
listenAddr = flag.String("listen", ":8080", "listen address")
informUrl = flag.String("inform", "http://unifi:8080/informUrl", "inform url")
)

func main() {
flag.Parse()

log.Println("Server is ready to handle requests at", *listenAddr)
log.Println("Inform URL at", *informUrl)

http.HandleFunc("/inform", informHandler)

log.Fatal(http.ListenAndServe(*listenAddr, nil))
}

func informHandler(w http.ResponseWriter, r *http.Request) {
log.Println(r)

if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

body, _ := ioutil.ReadAll(r.Body)

informResponse, _ := http.Post(*informUrl, "application/x-binary", bytes.NewReader(body))

log.Println(informResponse)
}

0 comments on commit 6673a1f

Please sign in to comment.