mirror of
https://github.com/fumiama/go-nd-portal.git
synced 2026-06-29 23:51:06 +08:00
fix
This commit is contained in:
20
portal.go
20
portal.go
@@ -25,6 +25,12 @@ type Portal struct {
|
|||||||
ip net.IP
|
ip net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type rsp struct {
|
||||||
|
Challenge string `json:"challenge"`
|
||||||
|
Ecode int `json:"ecode"`
|
||||||
|
Msg string `json:"error_msg"`
|
||||||
|
}
|
||||||
|
|
||||||
func NewPortal(name, password string, ipv4 net.IP) (*Portal, error) {
|
func NewPortal(name, password string, ipv4 net.IP) (*Portal, error) {
|
||||||
if len(ipv4) != 4 {
|
if len(ipv4) != 4 {
|
||||||
return nil, ErrIllegalIPv4
|
return nil, ErrIllegalIPv4
|
||||||
@@ -48,11 +54,6 @@ func (p *Portal) GetChallenge() (string, error) {
|
|||||||
if len(data) < 12 {
|
if len(data) < 12 {
|
||||||
return "", ErrUnexpectedChallengeResponse
|
return "", ErrUnexpectedChallengeResponse
|
||||||
}
|
}
|
||||||
type rsp struct {
|
|
||||||
Challenge string `json:"challenge"`
|
|
||||||
Ecode int `json:"ecode"`
|
|
||||||
Msg string `json:"error_msg"`
|
|
||||||
}
|
|
||||||
var r rsp
|
var r rsp
|
||||||
err = json.Unmarshal(data[11:len(data)-1], &r)
|
err = json.Unmarshal(data[11:len(data)-1], &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,18 +86,15 @@ func (p *Portal) Login(challenge string) error {
|
|||||||
if len(data) < 12 {
|
if len(data) < 12 {
|
||||||
return ErrUnexpectedLoginResponse
|
return ErrUnexpectedLoginResponse
|
||||||
}
|
}
|
||||||
type rsp struct {
|
|
||||||
Error string `json:"error"`
|
|
||||||
}
|
|
||||||
var r rsp
|
var r rsp
|
||||||
err = json.Unmarshal(data[11:len(data)-1], &r)
|
err = json.Unmarshal(data[11:len(data)-1], &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if r.Error == "ok" {
|
if r.Ecode != 0 {
|
||||||
return nil
|
return errors.New(r.Msg)
|
||||||
}
|
}
|
||||||
return errors.New(r.Error)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Portal) String() string {
|
func (p *Portal) String() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user