Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandzelter committed Jun 2, 2020
1 parent 67d5234 commit 1520624
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/reverse-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package main

import (
"bytes"
"encoding/json"
"io/ioutil"
"math/rand"
"net"
"net/http"
"bytes"

"github.com/dustin/go-coap"
)

var functions map[string][]string

type function_info struct {
Function_resource string `json:"function_resource"`
Function_resource string `json:"function_resource"`
Function_containers []string `json:"function_containers"`
}

Expand Down Expand Up @@ -68,43 +68,43 @@ func handleFunctionCall(l *net.UDPConn, a *net.UDPAddr, m *coap.Message) *coap.M
}

func main() {
functions = make(map[string][]string)
functions = make(map[string][]string)

mux := coap.NewServeMux()
mux.Handle("/functions", coap.FuncHandler(handleFunctionCall))
mux := coap.NewServeMux()
mux.Handle("/functions", coap.FuncHandler(handleFunctionCall))

go func() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
buf := new(bytes.Buffer)
buf.ReadFrom(r.Body)
newStr := buf.String()
go func() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
buf := new(bytes.Buffer)
buf.ReadFrom(r.Body)
newStr := buf.String()

var f function_info
err := json.Unmarshal([]byte(newStr), &f)
var f function_info
err := json.Unmarshal([]byte(newStr), &f)

if err != nil {
return
}
if err != nil {
return
}

if f.Function_resource[0] == '/' {
f.Function_resource = f.Function_resource[1:]
}
if f.Function_resource[0] == '/' {
f.Function_resource = f.Function_resource[1:]
}

functions[f.Function_resource] = f.Function_containers
functions[f.Function_resource] = f.Function_containers

mux.Handle(f.Function_resource, coap.FuncHandler(handleFunctionCall))
mux.Handle(f.Function_resource, coap.FuncHandler(handleFunctionCall))

return
return

}
})
}
})

http.ListenAndServe(":80", nil)
}()
http.ListenAndServe(":80", nil)
}()

func() {
coap.ListenAndServe("udp", ":5683", mux)
}()
func() {
coap.ListenAndServe("udp", ":5683", mux)
}()

}

0 comments on commit 1520624

Please sign in to comment.