Changed API, added folders and server file
This commit is contained in:
Binary file not shown.
@@ -1,37 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
StatusCode int `json:"statusCode"`
|
|
||||||
Headers map[string]string `json:"headers"`
|
|
||||||
Body string `json:"body"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func Handler() ([]byte, error) {
|
|
||||||
m := []Response{
|
|
||||||
Response{
|
|
||||||
StatusCode: 200,
|
|
||||||
Headers: map[string]string {"Content-Type": "application/json"},
|
|
||||||
Body: "This is the first task",
|
|
||||||
},
|
|
||||||
Response{
|
|
||||||
StatusCode: 200,
|
|
||||||
Headers: map[string]string {"Content-Type": "application/json"},
|
|
||||||
Body: "This is the second task",
|
|
||||||
}}
|
|
||||||
b, err := json.Marshal(m)
|
|
||||||
return b, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
b, err := Handler()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("error:", err)
|
|
||||||
}
|
|
||||||
os.Stdout.Write(b)
|
|
||||||
}
|
|
||||||
BIN
backend/GO_API/GO_API.exe
Normal file
BIN
backend/GO_API/GO_API.exe
Normal file
Binary file not shown.
40
backend/GO_API/server.go
Normal file
40
backend/GO_API/server.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/labstack/echo"
|
||||||
|
"github.com/labstack/echo/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Task struct {
|
||||||
|
Title string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
e := echo.New()
|
||||||
|
|
||||||
|
// Middleware
|
||||||
|
e.Use(middleware.Logger())
|
||||||
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
|
//CORS
|
||||||
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||||
|
AllowOrigins: []string{"*"},
|
||||||
|
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
|
||||||
|
}))
|
||||||
|
|
||||||
|
task := Task{
|
||||||
|
"First task",
|
||||||
|
"This is my first task in GO language",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Route => handler
|
||||||
|
e.GET("/", func(c echo.Context) error {
|
||||||
|
return c.String(http.StatusOK, "Title: " + task.Title + "\nDescription: " + task.Description)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Server
|
||||||
|
e.Start(":1323")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user