Some Go updates to the code and docstrings

Like replacing interface{} with any and adding docstrings
This commit is contained in:
2025-10-01 19:24:50 +01:00
parent d9b9e8a7f7
commit 9a9d486f9f
2 changed files with 14 additions and 7 deletions
+8 -4
View File
@@ -1,3 +1,5 @@
// Package bngsdk defines an API to interact with the BeamNG outgauge data in
// Go
package bngsdk
import (
@@ -8,8 +10,10 @@ import (
)
const (
UDP_IP = "127.0.0.1"
UDP_PORT = 4444
// UDPIP is the IP of the UDP outgauge server
UDPIP = "127.0.0.1"
// UDPPort is the port of the UDP outgauge server
UDPPort = 4444
)
type BNGSDK struct {
@@ -17,7 +21,7 @@ type BNGSDK struct {
Conn *net.UDPConn
Buffer []byte
Data *Outgauge
DataDict map[string]interface{}
DataDict map[string]any
}
func createUDPConnection(ip string, port int) (*net.UDPConn, *net.UDPAddr, error) {
@@ -66,7 +70,7 @@ func (sdk *BNGSDK) ReadData() error {
}
func (sdk *BNGSDK) Close() {
sdk.Conn.Close()
_ = sdk.Conn.Close()
}
// Init initializes a BeamNG SDK struct
+6 -3
View File
@@ -1,11 +1,13 @@
package bngsdk
// More documentation at https://go.beamng.com/protocols.
/* TODO
- OG_x Flags
- DL_x Flags
*/
// More documentation at https://go.beamng.com/protocols
// Outgauge describes the data served by the BeamNG outgauge server
type Outgauge struct {
Time uint32 // time in milliseconds (to check order)
Car [4]byte // Car name
@@ -29,8 +31,9 @@ type Outgauge struct {
ID int32 // optional - only if OutGauge ID is specified
}
func (o *Outgauge) ToMap() map[string]interface{} {
return map[string]interface{}{
// ToMap creates a map with the data in the Outgauge struct
func (o *Outgauge) ToMap() map[string]any {
return map[string]any{
"Time": o.Time, // time in milliseconds (to check order)
"Car": o.Car, // Car name
"Flags": o.Flags, // Info (see OG_x below)