Merge branch 'dynamic' into 'master'
Added dynamic endpoints for communication with modules See merge request murphg62/2023-ca400-murphg62-byrnm257!14
This commit is contained in:
commit
48cd5f51db
@ -66,13 +66,14 @@ func getSchema(c echo.Context) error {
|
|||||||
log.Fatalf("Failed to print Body: %v", err)
|
log.Fatalf("Failed to print Body: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSONBlob(http.StatusOK, body)
|
return c.JSONBlob(resp.StatusCode, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStats(c echo.Context) error {
|
func getComponent(c echo.Context) error {
|
||||||
key := c.Param("container")
|
container := c.Param("container")
|
||||||
|
component := c.Param("component")
|
||||||
|
|
||||||
requestURL := fmt.Sprintf("http://%s:8080", key)
|
requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component)
|
||||||
resp, err := http.Get(requestURL)
|
resp, err := http.Get(requestURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Request to container failed: %v", err)
|
log.Fatalf("Request to container failed: %v", err)
|
||||||
@ -88,6 +89,25 @@ func getStats(c echo.Context) error {
|
|||||||
return c.JSONBlob(http.StatusOK, body)
|
return c.JSONBlob(http.StatusOK, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postComponent(c echo.Context) error {
|
||||||
|
container := c.Param("container")
|
||||||
|
component := c.Param("component")
|
||||||
|
|
||||||
|
requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component)
|
||||||
|
resp, err := http.Post(requestURL, "application/json", c.Request().Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Request to container failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to print Body: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSONBlob(http.StatusOK, body)
|
||||||
|
}
|
||||||
|
|
||||||
func GetModules(db *sql.DB) echo.HandlerFunc {
|
func GetModules(db *sql.DB) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
@ -226,7 +246,8 @@ func main() {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.GET("/", homePage)
|
e.GET("/", homePage)
|
||||||
e.GET("/:container/schema", getSchema)
|
e.GET("/:container/schema", getSchema)
|
||||||
e.GET("/:container/stats", getStats)
|
e.GET("/component/:container/:component", getComponent)
|
||||||
|
e.POST("/component/:container/:component", postComponent)
|
||||||
e.GET("/modules", GetModules(db))
|
e.GET("/modules", GetModules(db))
|
||||||
e.POST("/user/register", RegisterUser(db))
|
e.POST("/user/register", RegisterUser(db))
|
||||||
e.POST("/user/login", LoginUser(db, jwtSecret))
|
e.POST("/user/login", LoginUser(db, jwtSecret))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user