-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (90 loc) · 2.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"io"
"os"
// structs "github.com/nextbillion-ai/nb-optimization-interface"
"github.com/nextbillion-ai/nb-optimization-interface/structs"
client "github.com/nextbillion-ai/nb-optimization-sdk/src"
// validations "github.com/nextbillion-ai/nb-optimization-interface/validations"
)
func mkUint64Ptr(value uint64) *uint64 {
return &value
}
func main() {
apikey := os.Getenv("APIKEY")
baseUrl := os.Getenv("BASEURL")
sdkClient := client.NewClient(baseUrl, apikey)
/*
{
"locations": {
"id": 50,
"description": "Test",
"location": "19.38972030,-99.14369731|19.42566371,-99.17081981|19.42436859,-99.13374095"
},
"vehicles": [{
"id": 1,
"start_index": 0,
"end_index": 2
}, {
"id": 2,
"start_index": 1,
"end_index": 2
}
],
"jobs": [{
"id": 1,
"location_index": 0
},{
"id": 2,
"location_index": 1
}
]
}
*/
// Create an instance of OptimizationPostInput
input := structs.OptimizationPostInput{
Locations: structs.Locations{
Id: 50,
AnyTypeLocation: "12.995431,77.491535|13.007678,77.571308|13.003177,77.619232",
Location: "12.995431,77.491535|13.007678,77.571308|13.003177,77.619232",
},
Vehicles: []structs.Vehicle{
{
Id: 1,
StartIndex: mkUint64Ptr(0),
EndIndex: mkUint64Ptr(2),
},
{
Id: 2,
StartIndex: mkUint64Ptr(1),
EndIndex: mkUint64Ptr(2),
},
},
Jobs: []structs.Job{
{
Id: 1,
LocationIndex: 0,
},
{
Id: 2,
LocationIndex: 1,
},
},
}
// Make a POST request
resp, err := sdkClient.MakeRequest(fmt.Sprintf("/optimise-mvrp?key=%s", apikey), "POST", input)
if resp != nil {
defer resp.Body.Close()
body, re := io.ReadAll(resp.Body)
if re != nil {
fmt.Printf("Error getting response body:%s\n", re)
}
fmt.Printf("response body: %s \n", string(body))
}
if err != nil {
fmt.Printf("Error making request:%s\n", err)
return
}
fmt.Println("Response status:", resp.Status)
}