154 lines
3.1 KiB
Go
154 lines
3.1 KiB
Go
package protocol
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Body interface{}
|
|
|
|
type (
|
|
GetUserCert struct {
|
|
UID string `json:"uid"`
|
|
}
|
|
|
|
GetUnreadMsgsInfo struct {
|
|
Page int `json:"page"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
GetMsg struct {
|
|
Num int `json:"num"`
|
|
}
|
|
|
|
SendMsg struct {
|
|
ToUID string `json:"to_uid"`
|
|
Subject []byte `json:"subject"`
|
|
Body []byte `json:"body"`
|
|
}
|
|
|
|
AnswerGetUserCert struct {
|
|
UID string `json:"uid"`
|
|
Certificate []byte `json:"certificate"`
|
|
}
|
|
|
|
StoreUserCert struct {
|
|
Certificate []byte `json:"certificate"`
|
|
}
|
|
|
|
AnswerGetUnreadMsgsInfo struct {
|
|
Page int `json:"page"`
|
|
NumPages int `json:"num_pages"`
|
|
MessagesInfo []MsgInfo `json:"messages_info"`
|
|
}
|
|
|
|
MsgInfo struct {
|
|
Num int `json:"num"`
|
|
FromUID string `json:"from_uid"`
|
|
Subject []byte `json:"subject"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
}
|
|
|
|
AnswerGetMsg struct {
|
|
FromUID string `json:"from_uid"`
|
|
ToUID string `json:"to_uid"`
|
|
Subject []byte `json:"subject"`
|
|
Body []byte `json:"body"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
}
|
|
|
|
PostRegister struct {
|
|
UID string `json:"uid"`
|
|
Password string `json:"password"`
|
|
Certificate []byte `json:"certificate"`
|
|
}
|
|
|
|
PostLogin struct {
|
|
UID string `json:"uid"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
ReportError struct {
|
|
ErrorMessage string `json:"error"`
|
|
}
|
|
)
|
|
|
|
func NewGetUserCert(UID string) GetUserCert {
|
|
return GetUserCert{
|
|
UID: UID,
|
|
}
|
|
}
|
|
|
|
func NewGetUnreadMsgsInfo(page int, pageSize int) GetUnreadMsgsInfo {
|
|
return GetUnreadMsgsInfo{
|
|
Page: page,
|
|
PageSize: pageSize}
|
|
}
|
|
|
|
func NewGetMsg(num int) GetMsg {
|
|
return GetMsg{
|
|
Num: num,
|
|
}
|
|
}
|
|
|
|
func NewSendMsg(toUID string, subject []byte, body []byte) SendMsg {
|
|
return SendMsg{
|
|
ToUID: toUID,
|
|
Subject: subject,
|
|
Body: body,
|
|
}
|
|
}
|
|
|
|
func NewAnswerGetUserCert(uid string, certificate []byte) AnswerGetUserCert {
|
|
return AnswerGetUserCert{
|
|
UID: uid,
|
|
Certificate: certificate,
|
|
}
|
|
}
|
|
|
|
func NewAnswerGetUnreadMsgsInfo(page int, numPages int, messagesInfo []MsgInfo) AnswerGetUnreadMsgsInfo {
|
|
return AnswerGetUnreadMsgsInfo{Page: page, NumPages: numPages, MessagesInfo: messagesInfo}
|
|
}
|
|
func NewMsgInfo(num int, fromUID string, subject []byte, timestamp time.Time) MsgInfo {
|
|
return MsgInfo{
|
|
Num: num,
|
|
FromUID: fromUID,
|
|
Subject: subject,
|
|
Timestamp: timestamp,
|
|
}
|
|
}
|
|
|
|
func NewPostRegister(UID string, Password string, Certificate []byte) PostRegister {
|
|
return PostRegister{
|
|
UID: UID,
|
|
Password: Password,
|
|
Certificate: Certificate,
|
|
}
|
|
}
|
|
func NewStoreUserCert(certificate []byte) StoreUserCert {
|
|
return StoreUserCert{
|
|
Certificate: certificate,
|
|
}
|
|
}
|
|
|
|
func NewPostLogin(UID string, Password string) PostLogin {
|
|
return PostLogin{
|
|
UID: UID,
|
|
Password: Password,
|
|
}
|
|
}
|
|
|
|
func NewAnswerGetMsg(fromUID, toUID string, subject []byte, body []byte, timestamp time.Time, last bool) AnswerGetMsg {
|
|
return AnswerGetMsg{
|
|
FromUID: fromUID,
|
|
ToUID: toUID,
|
|
Subject: subject,
|
|
Body: body,
|
|
Timestamp: timestamp,
|
|
}
|
|
}
|
|
|
|
func NewReportError(errorMessage string) ReportError {
|
|
return ReportError{
|
|
ErrorMessage: errorMessage,
|
|
}
|
|
}
|