62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package test
|
|
|
|
import (
|
|
"ai_scheduler/internal/entitys"
|
|
"ai_scheduler/internal/pkg/mapstructure"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.cdlsxd.cn/self-tools/l_request"
|
|
)
|
|
|
|
func Test_task(t *testing.T) {
|
|
var c entitys.TaskConfig
|
|
config := `{"param": {"type": "object", "required": ["number"], "properties": {"number": {"type": "string", "description": "订单编号/流水号"}}}, "request": {"url": "http://www.baidu.com/${number}", "headers": {"Authorization": "${authorization}"}, "method": "GET"}}`
|
|
err := json.Unmarshal([]byte(config), &c)
|
|
t.Log(err)
|
|
}
|
|
|
|
type configData struct {
|
|
Param map[string]interface{} `json:"param"`
|
|
Do map[string]interface{} `json:"do"`
|
|
}
|
|
|
|
func Test_task2(t *testing.T) {
|
|
var (
|
|
c l_request.Request
|
|
config configData
|
|
)
|
|
|
|
configJson := `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`
|
|
err := json.Unmarshal([]byte(configJson), &config)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
mapstructure.Decode(config.Do, &c)
|
|
t.Log(err)
|
|
}
|
|
|
|
func producer(ch chan<- int) {
|
|
for i := 0; i < 100; i++ {
|
|
ch <- i // 发送数据到通道
|
|
fmt.Printf("Sent: %d\n", i)
|
|
time.Sleep(500 * time.Millisecond) // 模拟生产延迟
|
|
}
|
|
close(ch) // 关闭通道,通知接收方数据发送完毕
|
|
}
|
|
|
|
func consumer(ch <-chan int) {
|
|
for v := range ch { // 阻塞等待数据,有数据立即处理
|
|
fmt.Printf("Received: %d\n", v)
|
|
}
|
|
}
|
|
|
|
func Test_a(t *testing.T) {
|
|
ch := make(chan int, 3) // 有缓冲通道(可选)
|
|
|
|
go producer(ch)
|
|
consumer(ch) // 主线程阻塞,直到通道关闭
|
|
}
|