feat: 实现 Go 与 JS/TS SDK 连接收发与其余接口
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package nixmsg
|
||||
|
||||
import "fmt"
|
||||
|
||||
// APIError 是带协议错误码的错误。
|
||||
type APIError struct {
|
||||
Code string
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
if e.Message == "" {
|
||||
return e.Code
|
||||
}
|
||||
return fmt.Sprintf("%s: %s", e.Code, e.Message)
|
||||
}
|
||||
|
||||
func apiErr(code, msg string) *APIError {
|
||||
return &APIError{Code: code, Message: msg}
|
||||
}
|
||||
|
||||
// 常用错误码(与 DEVELOPMENT 第 6.10 节一致)。
|
||||
const (
|
||||
CodeBodyTooLarge = "body_too_large"
|
||||
CodeFrameTooLarge = "frame_too_large"
|
||||
CodeMetaTooLarge = "meta_too_large"
|
||||
CodeRateLimited = "rate_limited"
|
||||
CodeBadRequest = "bad_request"
|
||||
CodeNotReady = "not_ready"
|
||||
CodeBusy = "busy"
|
||||
CodeSessionInvalid = "session_invalid"
|
||||
CodeBadCredentials = "bad_credentials"
|
||||
CodeQueueFull = "queue_full"
|
||||
CodeNotConnected = "not_connected"
|
||||
CodeClosed = "closed"
|
||||
CodeAuthFailed = "auth_failed"
|
||||
CodeKicked = "kicked"
|
||||
)
|
||||
|
||||
// AuthReason 是认证失败原因。
|
||||
type AuthReason string
|
||||
|
||||
const (
|
||||
AuthSessionInvalid AuthReason = "session_invalid"
|
||||
AuthBadCredentials AuthReason = "bad_credentials"
|
||||
)
|
||||
Reference in New Issue
Block a user