Example #1
0
func writedata(ProtoMessage *msgproto.Msg) {

	db, err := sql.Open("postgres", "user=postgres password='******' dbname=test sslmode=disable ")
	if err != nil {
		fmt.Println(err)
	}
	rows, err := db.Exec("INSERT INTO public.data values($1,$2,$3,to_timestamp($4))", ProtoMessage.GetId(), ProtoMessage.GetLat(), ProtoMessage.GetLong(), ProtoMessage.GetUtime())
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(rows)

}
Example #2
0
func createmessage() []byte {
	ProtoMessage := new(msgproto.Msg)
	ProtoMessage.Id = proto.Int32(12344)
	ProtoMessage.Lat = proto.Int64(12344)
	ProtoMessage.Long = proto.Int64(12344)
	ProtoMessage.Utime = proto.Int64(int64(time.Now().Unix()))
	data, err := proto.Marshal(ProtoMessage)
	if err != nil {
		fmt.Println(err)
	}
	return data

}
Example #3
0
func writedata(ProtoMessage *msgproto.Msg) {

	db, err := sql.Open("postgres", "user=postgres password='******' dbname=test sslmode=disable ")
	if err != nil {
		fmt.Println(err)
	}
	//var query string
	//string = "INSERT INTO bus_" + string(ProtoMessage.GetId()) + " values(" + strconv.FormatInt(ProtoMessage.GetLat(), 10) + "," + strconv.FormatInt(ProtoMessage.GetLong(), 10) + "," + strconv.FormatInt(ProtoMessage.GetUtime(), 10)
	rows, err := db.Exec("INSERT INTO $1 values($2,$3,to_timestamp($4))", ProtoMessage.GetId(), ProtoMessage.GetLat(), ProtoMessage.GetLong(), ProtoMessage.GetUtime())
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(rows)

}
Example #4
0
func handleRequest(conn net.Conn) {
	data := make([]byte, 4096)
	// Read the incoming connection into the buffer.
	n, err := conn.Read(data)
	if err != nil {
		fmt.Println("Error reading:", err.Error())
	}
	protodata := new(msgproto.Msg)
	err = proto.Unmarshal(data[0:n], protodata)
	fmt.Println(protodata.GetId())
	fmt.Println(protodata.GetLat())

	// Close the connection when you're done with it.
	conn.Close()
	//go writedata(protodata)

}