a41f938cec
As we have seen, dependencies version can prevent the build. We should user lock versions on dependencies that we know work: * Packages are vendored * Add Godep support * Added addtional install step in readme * Fix travis build error
50 lignes
919 o
Go
50 lignes
919 o
Go
package krpc
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/anacrolix/torrent/bencode"
|
|
)
|
|
|
|
var ErrorMethodUnknown = Error{
|
|
Code: 204,
|
|
Msg: "Method Unknown",
|
|
}
|
|
|
|
// Represented as a string or list in bencode.
|
|
type Error struct {
|
|
Code int
|
|
Msg string
|
|
}
|
|
|
|
var (
|
|
_ bencode.Unmarshaler = &Error{}
|
|
_ bencode.Marshaler = &Error{}
|
|
_ error = Error{}
|
|
)
|
|
|
|
func (e *Error) UnmarshalBencode(_b []byte) (err error) {
|
|
var _v interface{}
|
|
err = bencode.Unmarshal(_b, &_v)
|
|
if err != nil {
|
|
return
|
|
}
|
|
switch v := _v.(type) {
|
|
case []interface{}:
|
|
e.Code = int(v[0].(int64))
|
|
e.Msg = v[1].(string)
|
|
case string:
|
|
e.Msg = v
|
|
default:
|
|
err = fmt.Errorf(`KRPC error bencode value has unexpected type: %T`, _v)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (e Error) MarshalBencode() (ret []byte, err error) {
|
|
return bencode.Marshal([]interface{}{e.Code, e.Msg})
|
|
}
|
|
|
|
func (e Error) Error() string {
|
|
return fmt.Sprintf("KRPC error %d: %s", e.Code, e.Msg)
|
|
}
|