Little refactoring
This commit is contained in:
13
request.go
13
request.go
@@ -11,24 +11,31 @@ import (
|
||||
encoder "github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
type EmptyParams struct{}
|
||||
|
||||
func NewEmptyParams() *EmptyParams {
|
||||
return &EmptyParams{}
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Method string `json:"method" msgpack:"method"`
|
||||
Params any `json:"params,omitempty" msgpack:"params"`
|
||||
Auth *Auth `json:"auth,omitempty" msgpack:"auth"`
|
||||
}
|
||||
|
||||
func NewRequest() *Request {
|
||||
func NewEmptyRequest() *Request {
|
||||
req := &Request{}
|
||||
req.Auth = &Auth{}
|
||||
req.Params = NewEmptyParams()
|
||||
return req
|
||||
}
|
||||
|
||||
func (req *Request) Pack() ([]byte, error) {
|
||||
rBytes, err := encoder.Marshal(req)
|
||||
return rBytes, Err(err)
|
||||
return rBytes, err
|
||||
}
|
||||
|
||||
func (req *Request) JSON() []byte {
|
||||
func (req *Request) ToJson() []byte {
|
||||
jBytes, _ := json.Marshal(req)
|
||||
return jBytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user