rts-sim-testing-service/dynamics/http.go

35 lines
801 B
Go

package dynamics
import (
"bytes"
"encoding/json"
"fmt"
"go.uber.org/zap"
"joylink.club/bj-rtsts-server/config"
"net/http"
)
func SendTrainInitReq(info *InitTrainInfo) (int, *[]byte, error) {
defer func() {
if r := recover(); r != nil {
zap.S().Error("发送列车初始化请求失败", r)
}
}()
ip := config.Config.Dynamics.Ip
var port string
if config.Config.Dynamics.HttpPort != 0 {
port = fmt.Sprintf(":%d", config.Config.Dynamics.HttpPort)
}
uri := "/api/aerodynamics/init/train"
url := "http://" + ip + port + uri
data, _ := json.Marshal(info)
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(data))
var buf []byte
_, err := resp.Body.Read(buf)
if err != nil {
return resp.StatusCode, nil, err
}
return resp.StatusCode, &buf, resp.Body.Close()
}