opera-proxy/seclient/messages.go
Vladislav Yarmak fa5f109285 WIP
2021-03-25 20:29:37 +02:00

50 lines
747 B
Go

package seclient
import (
"encoding/json"
"errors"
"strconv"
)
const (
SE_STATUS_OK int64 = 0
)
type SEStatusPair struct {
Code int64
Message string
}
func (p *SEStatusPair) UnmarshalJSON(b []byte) error {
var tmp map[string]string
err := json.Unmarshal(b, &tmp)
if err != nil {
return err
}
if len(tmp) != 1 {
return errors.New("ambiguous status")
}
var strCode, strStatus string
for k, v := range tmp {
strCode = k
strStatus = v
}
code, err := strconv.ParseInt(strCode, 10, 64)
if err != nil {
return err
}
*p = SEStatusPair{
Code: code,
Message: strStatus,
}
return nil
}
type SERegisterSubscriberResponse struct {
Data interface{} `json:"data"`
Status SEStatusPair `json:"return_code"`
}