untested schema and chart component endpoints
This commit is contained in:
parent
5882ee8243
commit
334cf502ad
@ -4,6 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/text v0.8.0 // indirect
|
||||
|
||||
@ -2,6 +2,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
|
||||
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
|
||||
85
src/backend/moduleAPI.go
Normal file
85
src/backend/moduleAPI.go
Normal file
@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
||||
func getSchema(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
container := vars["container"]
|
||||
|
||||
//make get request to specified container
|
||||
url := fmt.Sprintf("http://%s", container)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
schema := &Schema{}
|
||||
err = proto.Unmarshal(body, schema)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(schema)
|
||||
}
|
||||
|
||||
func getStats(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
port := vars["port"]
|
||||
|
||||
|
||||
//make get request to specified container
|
||||
url := fmt.Sprintf("http://localhost:%d", port)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
stats := &ChartComponent{}
|
||||
err = proto.Unmarshal(body, stats)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(stats)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
func handleRequests() {
|
||||
myRouter := mux.NewRouter().StrictSlash(true)
|
||||
|
||||
myRouter.HandleFunc("/schema/{container}", getSchema)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":3000", myRouter))
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
fmt.Println("Module API...")
|
||||
handleRequests()
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user