28 lines
819 B
Go
28 lines
819 B
Go
package pkg
|
||
|
||
import (
|
||
"ai_scheduler/internal/entitys"
|
||
"encoding/json"
|
||
)
|
||
|
||
func JsonStringIgonErr(data interface{}) string {
|
||
return string(JsonByteIgonErr(data))
|
||
}
|
||
|
||
func JsonByteIgonErr(data interface{}) []byte {
|
||
dataByte, _ := json.Marshal(data)
|
||
return dataByte
|
||
}
|
||
|
||
// IsChannelClosed 检查给定的 channel 是否已经关闭
|
||
// 参数 ch: 要检查的 channel,类型为 chan entitys.ResponseData
|
||
// 返回值: bool 类型,true 表示 channel 已关闭,false 表示未关闭
|
||
func IsChannelClosed(ch chan entitys.ResponseData) bool {
|
||
select {
|
||
case _, ok := <-ch: // 尝试从 channel 中读取数据
|
||
return !ok // 如果 ok=false,说明 channel 已关闭
|
||
default: // 如果 channel 暂时无数据可读(但不一定关闭)
|
||
return false // channel 未关闭(但可能有数据未读取)
|
||
}
|
||
}
|