1 Star 0 Fork 0

kennyzhu2015/gosip

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
message.go 981 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhuwei6 提交于 2022-12-05 16:26 +08:00 . modify all
package testutils
import (
"fmt"
"strings"
"gitee.com/kennyzw/gosip/log"
"gitee.com/kennyzw/gosip/sip"
"gitee.com/kennyzw/gosip/sip/parser"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func Message(rawMsg []string) sip.Message {
msg, err := parser.ParseMessage([]byte(strings.Join(rawMsg, "\r\n")), log.NewDefaultLogrusLogger())
Expect(err).ToNot(HaveOccurred())
return msg
}
func Request(rawMsg []string) sip.Request {
msg := Message(rawMsg)
switch msg := msg.(type) {
case sip.Request:
return msg
case sip.Response:
Fail(fmt.Sprintf("%s is not a request", msg.Short()))
default:
Fail(fmt.Sprintf("%s is not a request", msg.Short()))
}
return nil
}
func Response(rawMsg []string) sip.Response {
msg := Message(rawMsg)
switch msg := msg.(type) {
case sip.Response:
return msg
case sip.Request:
Fail(fmt.Sprintf("%s is not a response", msg.Short()))
default:
Fail(fmt.Sprintf("%s is not a response", msg.Short()))
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kennyzw/gosip.git
git@gitee.com:kennyzw/gosip.git
kennyzw
gosip
gosip
240694758ecc

搜索帮助