-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (51 loc) · 1019 Bytes
/
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
package main
import (
"fmt"
"log"
"math/rand"
"time"
"github.com/adarsh-jaiss/microservice-toll-calculator/types"
"github.com/gorilla/websocket"
)
const wsEndpoint = "ws://127.0.0.1:30000/ws"
var sendInterval = time.Second * 5
func genCord() float64 {
n := float64(rand.Intn(100)+1)
f := rand.Float64()
return n + f
}
func Location() (float64,float64){
return genCord(),genCord()
}
func generateOBUID(n int) []int {
ids := make([]int,n)
for i := 0; i < n; i++ {
ids[i] = rand.Intn(999999)
}
return ids
}
func main() {
obuIDs := generateOBUID(20)
conn, _, err := websocket.DefaultDialer.Dial(wsEndpoint,nil)
if err!= nil{
log.Fatal(err)
}
for{
for i := 0; i < len(obuIDs); i++ {
lat,long := Location()
data := types.OBUData{
OBUID: obuIDs[i],
Latitiude: lat,
Longitude: long,
}
fmt.Printf("%+v\n",data)
if err := conn.WriteJSON(data); err!= nil{
log.Fatal(err)
}
}
time.Sleep(sendInterval)
}
}
func init() {
rand.Seed(time.Now().UnixNano())
}