Spaces:
Sleeping
Sleeping
Commit
·
b5b4a38
1
Parent(s):
5d966be
reads incoming request json if user specifys correctly
Browse files- main.go +0 -29
- server.go +40 -0
- test/main.go +47 -3
main.go
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
package main
|
2 |
-
|
3 |
-
import (
|
4 |
-
"fmt"
|
5 |
-
"os"
|
6 |
-
|
7 |
-
"github.com/go-gota/gota/dataframe"
|
8 |
-
"github.com/gofiber/fiber/v2"
|
9 |
-
)
|
10 |
-
|
11 |
-
func main() {
|
12 |
-
app := fiber.New()
|
13 |
-
|
14 |
-
app.Get("/", func(c *fiber.Ctx) error {
|
15 |
-
filePath := "test/iris.csv"
|
16 |
-
|
17 |
-
file, err := os.Open(filePath)
|
18 |
-
if err != nil {
|
19 |
-
panic(err)
|
20 |
-
}
|
21 |
-
|
22 |
-
df := dataframe.ReadCSV(file)
|
23 |
-
fmt.Println(df)
|
24 |
-
return c.SendString("No error")
|
25 |
-
})
|
26 |
-
|
27 |
-
app.Listen(":3000")
|
28 |
-
|
29 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.go
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
package main
|
2 |
+
|
3 |
+
import (
|
4 |
+
"fmt"
|
5 |
+
|
6 |
+
"github.com/gofiber/fiber/v2"
|
7 |
+
)
|
8 |
+
|
9 |
+
type RequestPayload struct {
|
10 |
+
CSVData string `json:"csv_data"`
|
11 |
+
Features []string `json:"features"`
|
12 |
+
Target string `json:"target"`
|
13 |
+
Epochs int `json:"epochs"`
|
14 |
+
HiddenSize int `json:"hidden_size"`
|
15 |
+
LearningRate float64 `json:"learning_rate"`
|
16 |
+
ActivationFunc string `json:"activation_func"`
|
17 |
+
}
|
18 |
+
|
19 |
+
func main() {
|
20 |
+
app := fiber.New()
|
21 |
+
|
22 |
+
app.Post("/", func(c *fiber.Ctx) error {
|
23 |
+
|
24 |
+
requestData := new(RequestPayload)
|
25 |
+
|
26 |
+
// parse json request data into requestData struct
|
27 |
+
if err := c.BodyParser(requestData); err != nil {
|
28 |
+
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
29 |
+
"error": "Invalid JSON data",
|
30 |
+
})
|
31 |
+
}
|
32 |
+
|
33 |
+
fmt.Println(requestData)
|
34 |
+
|
35 |
+
return c.SendString("No error")
|
36 |
+
})
|
37 |
+
|
38 |
+
app.Listen(":3000")
|
39 |
+
|
40 |
+
}
|
test/main.go
CHANGED
@@ -1,16 +1,60 @@
|
|
1 |
package main
|
2 |
|
3 |
import (
|
|
|
|
|
4 |
"fmt"
|
5 |
"io/ioutil"
|
6 |
"net/http"
|
7 |
)
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
func main() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
if err != nil {
|
15 |
panic(err)
|
16 |
}
|
|
|
1 |
package main
|
2 |
|
3 |
import (
|
4 |
+
"bytes"
|
5 |
+
"encoding/json"
|
6 |
"fmt"
|
7 |
"io/ioutil"
|
8 |
"net/http"
|
9 |
)
|
10 |
|
11 |
+
type RequestPayload struct {
|
12 |
+
CSVData string `json:"csv_data"`
|
13 |
+
Features []string `json:"features"`
|
14 |
+
Target string `json:"target"`
|
15 |
+
Epochs int `json:"epochs"`
|
16 |
+
HiddenSize int `json:"hidden_size"`
|
17 |
+
LearningRate float64 `json:"learning_rate"`
|
18 |
+
ActivationFunc string `json:"activation_func"`
|
19 |
+
}
|
20 |
+
|
21 |
func main() {
|
22 |
+
filePath := "iris.csv"
|
23 |
+
|
24 |
+
csvBytes, err := ioutil.ReadFile(filePath)
|
25 |
+
if err != nil {
|
26 |
+
fmt.Println("Error reading CSV file: ", err)
|
27 |
+
return
|
28 |
+
}
|
29 |
+
|
30 |
+
csvString := string(csvBytes)
|
31 |
+
features := []string{"petal length", "sepal length", "sepal width", "petal width"}
|
32 |
+
target := "species"
|
33 |
+
epochs := 100
|
34 |
+
hiddenSize := 8
|
35 |
+
learningRate := 0.1
|
36 |
+
activationFunc := "tanh"
|
37 |
+
|
38 |
+
payload := RequestPayload{
|
39 |
+
CSVData: csvString,
|
40 |
+
Features: features,
|
41 |
+
Target: target,
|
42 |
+
Epochs: epochs,
|
43 |
+
HiddenSize: hiddenSize,
|
44 |
+
LearningRate: learningRate,
|
45 |
+
ActivationFunc: activationFunc,
|
46 |
+
}
|
47 |
+
|
48 |
+
jsonPayload, err := json.Marshal(payload)
|
49 |
+
if err != nil {
|
50 |
+
panic(err)
|
51 |
+
}
|
52 |
|
53 |
+
r, err := http.Post(
|
54 |
+
"http://127.0.0.1:3000/",
|
55 |
+
"application/json",
|
56 |
+
bytes.NewBuffer(jsonPayload),
|
57 |
+
)
|
58 |
if err != nil {
|
59 |
panic(err)
|
60 |
}
|