数据 输入输出 处理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

package testUnit
import (
"encoding/json"
"fmt"
"goInOut/models"
"goInOut/utils"
"testing"
"time"
)
// 定义一个结构体,包含嵌套的结构体字段
type Person struct {
Name Name `json:"name"`
}
type Name struct {
First string `json:"first"`
Last string `json:"last"`
}
func Test_httpProxy(t *testing.T) {
}
func Test_template(t *testing.T) {
// 创建一个Person实例
person := Person{
Name: Name{
First: "John",
Last: "Doe",
},
}
templateStr := "Hello, {{.Name.First}} !"
sbs, err := utils.TextTemplateMatch(person, templateStr)
println(sbs)
if err != nil {
fmt.Println(err.Error())
}
}
func Test_timeHandler(t *testing.T) {
rawMsg := `{
"userId": "ce2d7eb2-e56e-422e-8bbe-95dfa18e32f8",
"thingId": "14862308-083e-46e1-a422-d7d6a1e2825d",
"dimensionId": "47386f69-c5aa-4ae7-b6cc-0490a1dc0b14",
"dimCapId": "0d561c0b-4dca-4104-abc0-1f0c40a71382",
"capId": "d4965875-354b-4294-87f4-c4ba9f9260ab",
"deviceId": "9c43a09c-3c65-42d3-9a54-42b87e0e5af2",
"scheduleId": "1cfebf18-81a2-489e-bcfb-efc294d8ce3d",
"taskId": "b58858ed-9e23-4ac9-9f9c-44f9e057aee9",
"jobId": 1,
"jobRepeatId": 1,
"triggerTime": "2024-12-04T18:23:04+16:00",
"realTime": "0001-01-01T00:00:00Z",
"finishTime": "2024-12-04T10:23:07.909922675+08:00",
"seq": 0,
"released": false,
"data": {
"type": 1,
"data": {
"physicalvalue": 0
},
"result": {
"code": 0,
"msg": "",
"detail": null,
"errTimes": 0,
"dropped": false
}
}
}`
iotaData := models.IotaData{}
json.Unmarshal([]byte(rawMsg), &iotaData)
var cstZone = time.FixedZone("CST", 8*3600) // 东八区
time := iotaData.TriggerTime.In(cstZone).Format("2006-01-02T15:04:05.000+0800")
println(time)
}