格式化stringer生成的文件
This commit is contained in:
parent
b8940243d0
commit
406b0f4be0
@ -1,62 +0,0 @@
|
||||
// Code generated by "stringer -type=AppMessageType -linecomment=true"; DO NOT EDIT.
|
||||
|
||||
package openwechat
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[AppMsgTypeText-1]
|
||||
_ = x[AppMsgTypeImg-2]
|
||||
_ = x[AppMsgTypeAudio-3]
|
||||
_ = x[AppMsgTypeVideo-4]
|
||||
_ = x[AppMsgTypeUrl-5]
|
||||
_ = x[AppMsgTypeAttach-6]
|
||||
_ = x[AppMsgTypeOpen-7]
|
||||
_ = x[AppMsgTypeEmoji-8]
|
||||
_ = x[AppMsgTypeVoiceRemind-9]
|
||||
_ = x[AppMsgTypeScanGood-10]
|
||||
_ = x[AppMsgTypeGood-13]
|
||||
_ = x[AppMsgTypeEmotion-15]
|
||||
_ = x[AppMsgTypeCardTicket-16]
|
||||
_ = x[AppMsgTypeRealtimeShareLocation-17]
|
||||
_ = x[AppMsgTypeTransfers-2000]
|
||||
_ = x[AppMsgTypeRedEnvelopes-2001]
|
||||
_ = x[AppMsgTypeReaderType-100001]
|
||||
}
|
||||
|
||||
const (
|
||||
_AppMessageType_name_0 = "文本消息图片消息语音消息视频消息文章消息附件消息Open表情消息VoiceRemindScanGood"
|
||||
_AppMessageType_name_1 = "Good"
|
||||
_AppMessageType_name_2 = "Emotion名片消息地理位置消息"
|
||||
_AppMessageType_name_3 = "转账消息红包消息"
|
||||
_AppMessageType_name_4 = "自定义的消息"
|
||||
)
|
||||
|
||||
var (
|
||||
_AppMessageType_index_0 = [...]uint8{0, 12, 24, 36, 48, 60, 72, 76, 88, 99, 107}
|
||||
_AppMessageType_index_2 = [...]uint8{0, 7, 19, 37}
|
||||
_AppMessageType_index_3 = [...]uint8{0, 12, 24}
|
||||
)
|
||||
|
||||
func (i AppMessageType) String() string {
|
||||
switch {
|
||||
case 1 <= i && i <= 10:
|
||||
i -= 1
|
||||
return _AppMessageType_name_0[_AppMessageType_index_0[i]:_AppMessageType_index_0[i+1]]
|
||||
case i == 13:
|
||||
return _AppMessageType_name_1
|
||||
case 15 <= i && i <= 17:
|
||||
i -= 15
|
||||
return _AppMessageType_name_2[_AppMessageType_index_2[i]:_AppMessageType_index_2[i+1]]
|
||||
case 2000 <= i && i <= 2001:
|
||||
i -= 2000
|
||||
return _AppMessageType_name_3[_AppMessageType_index_3[i]:_AppMessageType_index_3[i+1]]
|
||||
case i == 100001:
|
||||
return _AppMessageType_name_4
|
||||
default:
|
||||
return "AppMessageType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
}
|
27
base_response.go
Normal file
27
base_response.go
Normal file
@ -0,0 +1,27 @@
|
||||
package openwechat
|
||||
|
||||
type Ret int
|
||||
|
||||
const (
|
||||
ticketError Ret = -14 // ticket error
|
||||
paramError Ret = 1 // param error
|
||||
failedLoginWarn Ret = 1100 // failed login warn
|
||||
failedLoginCheck Ret = 1101 // failed login check
|
||||
cookieInvalid Ret = 1102 // cookie invalid
|
||||
loginEnvAbnormality Ret = 1203 // login environmental abnormality
|
||||
optTooOften Ret = 1205 // operate too often
|
||||
)
|
||||
|
||||
// BaseResponse 大部分返回对象都携带该信息
|
||||
type BaseResponse struct {
|
||||
Ret Ret
|
||||
ErrMsg string
|
||||
}
|
||||
|
||||
func (b BaseResponse) Ok() bool {
|
||||
return b.Ret == 0
|
||||
}
|
||||
|
||||
func (b BaseResponse) Error() string {
|
||||
return b.Ret.String()
|
||||
}
|
4
generate.go
Normal file
4
generate.go
Normal file
@ -0,0 +1,4 @@
|
||||
package openwechat
|
||||
|
||||
|
||||
//go:generate stringer -type=MessageType,Ret,AppMessageType -linecomment=true -output=stringer.go
|
@ -45,9 +45,6 @@ type MessageType int
|
||||
// AppMessageType 以Go惯用形式定义了PC微信所有的官方App消息类型。
|
||||
type AppMessageType int
|
||||
|
||||
//go:generate stringer -type=MessageType -linecomment=true
|
||||
//go:generate stringer -type=AppMessageType -linecomment=true
|
||||
|
||||
// https://res.wx.qq.com/a/wx_fed/webwx/res/static/js/index_c7d281c.js
|
||||
// MSGTYPE_TEXT
|
||||
// MSGTYPE_IMAGE
|
||||
@ -103,7 +100,6 @@ const (
|
||||
AppMsgTypeTransfers AppMessageType = 2000 // 转账消息
|
||||
AppMsgTypeRedEnvelopes AppMessageType = 2001 // 红包消息
|
||||
AppMsgTypeReaderType AppMessageType = 100001 //自定义的消息
|
||||
|
||||
)
|
||||
|
||||
// 登录状态
|
||||
|
93
items.go
93
items.go
@ -1,8 +1,7 @@
|
||||
package openwechat
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -20,28 +19,6 @@ type LoginInfo struct {
|
||||
PassTicket string `xml:"pass_ticket"`
|
||||
}
|
||||
|
||||
// errors
|
||||
const (
|
||||
errParamError = "param error"
|
||||
errTicketError = "ticket error"
|
||||
errLoginEnvError = "login env error"
|
||||
errLoginFailedWarn = "failed login warn"
|
||||
errLoginFailedCheck = "failed login check"
|
||||
errCookieInvalidError = "cookie invalid error"
|
||||
errOptTooOften = "opt too often"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrParamError = errors.New(errParamError)
|
||||
ErrTicketError = errors.New(errTicketError)
|
||||
ErrLoginEnvError = errors.New(errLoginEnvError)
|
||||
ErrLoginFailedWarn = errors.New(errLoginFailedWarn)
|
||||
ErrLoginFailedCheck = errors.New(errLoginFailedCheck)
|
||||
ErrCookieInvalidError = errors.New(errCookieInvalidError)
|
||||
ErrOptTooOften = errors.New(errOptTooOften)
|
||||
ErrBaseResponseError error
|
||||
)
|
||||
|
||||
func (l LoginInfo) Ok() bool {
|
||||
return l.Ret == 0
|
||||
}
|
||||
@ -57,47 +34,6 @@ type BaseRequest struct {
|
||||
Sid, Skey, DeviceID string
|
||||
}
|
||||
|
||||
// BaseResponse 大部分返回对象都携带该信息
|
||||
type BaseResponse struct {
|
||||
Ret int
|
||||
ErrMsg string
|
||||
}
|
||||
|
||||
func (b BaseResponse) Ok() bool {
|
||||
return b.Ret == 0
|
||||
}
|
||||
|
||||
func (b BaseResponse) Error() string {
|
||||
if err := getResponseErrorWithRetCode(b.Ret); err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getResponseErrorWithRetCode(code int) error {
|
||||
switch code {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return ErrParamError
|
||||
case -14:
|
||||
return ErrTicketError
|
||||
case 1100:
|
||||
return ErrLoginFailedWarn
|
||||
case 1101:
|
||||
return ErrLoginFailedCheck
|
||||
case 1102:
|
||||
return ErrCookieInvalidError
|
||||
case 1203:
|
||||
return ErrLoginEnvError
|
||||
case 1205:
|
||||
return ErrOptTooOften
|
||||
default:
|
||||
ErrBaseResponseError = fmt.Errorf("base response ret code %d", code)
|
||||
return ErrBaseResponseError
|
||||
}
|
||||
}
|
||||
|
||||
type SyncKey struct {
|
||||
Count int
|
||||
List []struct{ Key, Val int64 }
|
||||
@ -156,36 +92,21 @@ type SyncCheckResponse struct {
|
||||
Selector string
|
||||
}
|
||||
|
||||
func (s *SyncCheckResponse) Success() bool {
|
||||
func (s SyncCheckResponse) Success() bool {
|
||||
return s.RetCode == "0"
|
||||
}
|
||||
|
||||
func (s *SyncCheckResponse) NorMal() bool {
|
||||
func (s SyncCheckResponse) NorMal() bool {
|
||||
return s.Success() && s.Selector == "0"
|
||||
}
|
||||
|
||||
// 实现error接口
|
||||
func (s *SyncCheckResponse) Error() string {
|
||||
switch s.RetCode {
|
||||
case "0":
|
||||
func (s SyncCheckResponse) Error() string {
|
||||
i, err := strconv.ParseInt(s.RetCode, 16, 10)
|
||||
if err != nil {
|
||||
return ""
|
||||
case "1":
|
||||
return errParamError
|
||||
case "-14":
|
||||
return errTicketError
|
||||
case "1100":
|
||||
return errLoginFailedWarn
|
||||
case "1101":
|
||||
return errLoginFailedCheck
|
||||
case "1102":
|
||||
return errCookieInvalidError
|
||||
case "1203":
|
||||
return errLoginEnvError
|
||||
case "1205":
|
||||
return errOptTooOften
|
||||
default:
|
||||
return fmt.Sprintf("sync check response error code %s", s.RetCode)
|
||||
}
|
||||
return Ret(i).String()
|
||||
}
|
||||
|
||||
type WebWxSyncResponse struct {
|
||||
|
@ -1,55 +0,0 @@
|
||||
// Code generated by "stringer -type=MessageType -linecomment=true"; DO NOT EDIT.
|
||||
|
||||
package openwechat
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[MsgTypeText-1]
|
||||
_ = x[MsgTypeImage-3]
|
||||
_ = x[MsgTypeVoice-34]
|
||||
_ = x[MsgTypeVerify-37]
|
||||
_ = x[MsgTypePossibleFriend-40]
|
||||
_ = x[MsgTypeShareCard-42]
|
||||
_ = x[MsgTypeVideo-43]
|
||||
_ = x[MsgTypeEmoticon-47]
|
||||
_ = x[MsgTypeLocation-48]
|
||||
_ = x[MsgTypeApp-49]
|
||||
_ = x[MsgTypeVoip-50]
|
||||
_ = x[MsgTypeVoipNotify-52]
|
||||
_ = x[MsgTypeVoipInvite-53]
|
||||
_ = x[MsgTypeMicroVideo-62]
|
||||
_ = x[MsgTypeSys-10000]
|
||||
_ = x[MsgTypeRecalled-10002]
|
||||
}
|
||||
|
||||
const _MessageType_name = "文本消息图片消息语音消息认证消息好友推荐消息名片消息视频消息表情消息地理位置消息APP消息VOIP消息VOIP结束消息VOIP邀请小视频消息系统消息消息撤回"
|
||||
|
||||
var _MessageType_map = map[MessageType]string{
|
||||
1: _MessageType_name[0:12],
|
||||
3: _MessageType_name[12:24],
|
||||
34: _MessageType_name[24:36],
|
||||
37: _MessageType_name[36:48],
|
||||
40: _MessageType_name[48:66],
|
||||
42: _MessageType_name[66:78],
|
||||
43: _MessageType_name[78:90],
|
||||
47: _MessageType_name[90:102],
|
||||
48: _MessageType_name[102:120],
|
||||
49: _MessageType_name[120:129],
|
||||
50: _MessageType_name[129:139],
|
||||
52: _MessageType_name[139:155],
|
||||
53: _MessageType_name[155:165],
|
||||
62: _MessageType_name[165:180],
|
||||
10000: _MessageType_name[180:192],
|
||||
10002: _MessageType_name[192:204],
|
||||
}
|
||||
|
||||
func (i MessageType) String() string {
|
||||
if str, ok := _MessageType_map[i]; ok {
|
||||
return str
|
||||
}
|
||||
return "MessageType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
153
stringer.go
Normal file
153
stringer.go
Normal file
@ -0,0 +1,153 @@
|
||||
// Code generated by "stringer -type=MessageType,Ret,AppMessageType -linecomment=true -output=stringer.go"; DO NOT EDIT.
|
||||
|
||||
package openwechat
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[MsgTypeText-1]
|
||||
_ = x[MsgTypeImage-3]
|
||||
_ = x[MsgTypeVoice-34]
|
||||
_ = x[MsgTypeVerify-37]
|
||||
_ = x[MsgTypePossibleFriend-40]
|
||||
_ = x[MsgTypeShareCard-42]
|
||||
_ = x[MsgTypeVideo-43]
|
||||
_ = x[MsgTypeEmoticon-47]
|
||||
_ = x[MsgTypeLocation-48]
|
||||
_ = x[MsgTypeApp-49]
|
||||
_ = x[MsgTypeVoip-50]
|
||||
_ = x[MsgTypeVoipNotify-52]
|
||||
_ = x[MsgTypeVoipInvite-53]
|
||||
_ = x[MsgTypeMicroVideo-62]
|
||||
_ = x[MsgTypeSys-10000]
|
||||
_ = x[MsgTypeRecalled-10002]
|
||||
}
|
||||
|
||||
const _MessageType_name = "文本消息图片消息语音消息认证消息好友推荐消息名片消息视频消息表情消息地理位置消息APP消息VOIP消息VOIP结束消息VOIP邀请小视频消息系统消息消息撤回"
|
||||
|
||||
var _MessageType_map = map[MessageType]string{
|
||||
1: _MessageType_name[0:12],
|
||||
3: _MessageType_name[12:24],
|
||||
34: _MessageType_name[24:36],
|
||||
37: _MessageType_name[36:48],
|
||||
40: _MessageType_name[48:66],
|
||||
42: _MessageType_name[66:78],
|
||||
43: _MessageType_name[78:90],
|
||||
47: _MessageType_name[90:102],
|
||||
48: _MessageType_name[102:120],
|
||||
49: _MessageType_name[120:129],
|
||||
50: _MessageType_name[129:139],
|
||||
52: _MessageType_name[139:155],
|
||||
53: _MessageType_name[155:165],
|
||||
62: _MessageType_name[165:180],
|
||||
10000: _MessageType_name[180:192],
|
||||
10002: _MessageType_name[192:204],
|
||||
}
|
||||
|
||||
func (i MessageType) String() string {
|
||||
if str, ok := _MessageType_map[i]; ok {
|
||||
return str
|
||||
}
|
||||
return "MessageType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[ticketError - -14]
|
||||
_ = x[paramError-1]
|
||||
_ = x[failedLoginWarn-1100]
|
||||
_ = x[failedLoginCheck-1101]
|
||||
_ = x[cookieInvalid-1102]
|
||||
_ = x[loginEnvAbnormality-1203]
|
||||
_ = x[optTooOften-1205]
|
||||
}
|
||||
|
||||
const (
|
||||
_Ret_name_0 = "ticket error"
|
||||
_Ret_name_1 = "param error"
|
||||
_Ret_name_2 = "failed login warnfailed login Checkcookie invalid"
|
||||
_Ret_name_3 = "login environmental abnormality"
|
||||
_Ret_name_4 = "operate too often"
|
||||
)
|
||||
|
||||
var (
|
||||
_Ret_index_2 = [...]uint8{0, 17, 35, 49}
|
||||
)
|
||||
|
||||
func (r Ret) String() string {
|
||||
switch {
|
||||
case r == -14:
|
||||
return _Ret_name_0
|
||||
case r == 1:
|
||||
return _Ret_name_1
|
||||
case 1100 <= r && r <= 1102:
|
||||
r -= 1100
|
||||
return _Ret_name_2[_Ret_index_2[r]:_Ret_index_2[r+1]]
|
||||
case r == 1203:
|
||||
return _Ret_name_3
|
||||
case r == 1205:
|
||||
return _Ret_name_4
|
||||
default:
|
||||
return "Ret(" + strconv.FormatInt(int64(r), 10) + ")"
|
||||
}
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[AppMsgTypeText-1]
|
||||
_ = x[AppMsgTypeImg-2]
|
||||
_ = x[AppMsgTypeAudio-3]
|
||||
_ = x[AppMsgTypeVideo-4]
|
||||
_ = x[AppMsgTypeUrl-5]
|
||||
_ = x[AppMsgTypeAttach-6]
|
||||
_ = x[AppMsgTypeOpen-7]
|
||||
_ = x[AppMsgTypeEmoji-8]
|
||||
_ = x[AppMsgTypeVoiceRemind-9]
|
||||
_ = x[AppMsgTypeScanGood-10]
|
||||
_ = x[AppMsgTypeGood-13]
|
||||
_ = x[AppMsgTypeEmotion-15]
|
||||
_ = x[AppMsgTypeCardTicket-16]
|
||||
_ = x[AppMsgTypeRealtimeShareLocation-17]
|
||||
_ = x[AppMsgTypeTransfers-2000]
|
||||
_ = x[AppMsgTypeRedEnvelopes-2001]
|
||||
_ = x[AppMsgTypeReaderType-100001]
|
||||
}
|
||||
|
||||
const (
|
||||
_AppMessageType_name_0 = "文本消息图片消息语音消息视频消息文章消息附件消息Open表情消息VoiceRemindScanGood"
|
||||
_AppMessageType_name_1 = "Good"
|
||||
_AppMessageType_name_2 = "Emotion名片消息地理位置消息"
|
||||
_AppMessageType_name_3 = "转账消息红包消息"
|
||||
_AppMessageType_name_4 = "自定义的消息"
|
||||
)
|
||||
|
||||
var (
|
||||
_AppMessageType_index_0 = [...]uint8{0, 12, 24, 36, 48, 60, 72, 76, 88, 99, 107}
|
||||
_AppMessageType_index_2 = [...]uint8{0, 7, 19, 37}
|
||||
_AppMessageType_index_3 = [...]uint8{0, 12, 24}
|
||||
)
|
||||
|
||||
func (i AppMessageType) String() string {
|
||||
switch {
|
||||
case 1 <= i && i <= 10:
|
||||
i -= 1
|
||||
return _AppMessageType_name_0[_AppMessageType_index_0[i]:_AppMessageType_index_0[i+1]]
|
||||
case i == 13:
|
||||
return _AppMessageType_name_1
|
||||
case 15 <= i && i <= 17:
|
||||
i -= 15
|
||||
return _AppMessageType_name_2[_AppMessageType_index_2[i]:_AppMessageType_index_2[i+1]]
|
||||
case 2000 <= i && i <= 2001:
|
||||
i -= 2000
|
||||
return _AppMessageType_name_3[_AppMessageType_index_3[i]:_AppMessageType_index_3[i+1]]
|
||||
case i == 100001:
|
||||
return _AppMessageType_name_4
|
||||
default:
|
||||
return "AppMessageType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user