Documentation ¶
Overview ¶
Package dahuarpc is a client library for Dahua's RPC API.
Index ¶
- Variables
- func Cookie(session string) string
- func DoRaw(ctx context.Context, rb RequestBuilder, httpClient *http.Client, urL string) (io.ReadCloser, error)
- func ExtractFilePathTags(filePath string) []string
- func GetCurrentTime(ctx context.Context, c Conn) (string, error)
- func KeepAlive(ctx context.Context, c Conn) (int, error)
- func LoadFileURL(u *url.URL, filePath string) string
- func Login(ctx context.Context, conn ConnLogin, username, password string) error
- func LoginURL(u *url.URL) string
- func Logout(ctx context.Context, c Conn) (bool, error)
- func SecondLogin(ctx context.Context, c Conn, ...) error
- func URL(u *url.URL) string
- type AuthParam
- type Cache
- type Client
- type ClientState
- type Config
- type ConfigFunc
- type Conn
- type ConnLogin
- type ConnSession
- type ErrorType
- type FileClient
- type Integer
- type LoginError
- type Request
- type RequestBuilder
- func (rb RequestBuilder) ID(id int) RequestBuilder
- func (rb RequestBuilder) Object(object int64) RequestBuilder
- func (rb RequestBuilder) Option(key string, value any) RequestBuilder
- func (rb RequestBuilder) Params(params any) RequestBuilder
- func (rb RequestBuilder) Session(session string) RequestBuilder
- type Response
- type ResponseError
- type ResponseResult
- type ResponseSession
- type State
- type TimeSection
- type Timestamp
Constants ¶
This section is empty.
Variables ¶
var ( ErrLoginUserOrPasswordNotValid = newLoginError("User or password not valid") ErrLoginUserNotValid = newLoginError("User not valid") ErrLoginPasswordNotValid = newLoginError("Password not valid") ErrLoginInBlackList = newLoginError("User in blackList") ErrLoginHasBeedUsed = newLoginError("User has be used") ErrLoginHasBeenLocked = newLoginError("User locked") )
var (
ErrClientClosed = errors.New("client closed")
)
var (
ErrRequestFailed = errors.New("request failed")
)
Functions ¶
func DoRaw ¶
func DoRaw(ctx context.Context, rb RequestBuilder, httpClient *http.Client, urL string) (io.ReadCloser, error)
DoRaw executes the RPC request.
func ExtractFilePathTags ¶
ExtractFilePathTags extracts tags from the file path. Tags are strings surrounded by brackets
func LoadFileURL ¶
LoadFileURL is the HTTP URL for accessing files. The file path must be absolute.
func SecondLogin ¶
Types ¶
type AuthParam ¶
type AuthParam struct { Encryption string `json:"encryption"` Random string `json:"random"` Realm string `json:"realm"` }
func (AuthParam) HashPassword ¶
HashPassword runs the hashing algorithm for the password.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (Client) CloseNoWait ¶
CloseNoWait closes the connection without waiting for it to finish closing.
func (Client) Do ¶
func (c Client) Do(ctx context.Context, rb RequestBuilder) (io.ReadCloser, error)
type ClientState ¶
type ConfigFunc ¶
type ConfigFunc func(c *Config)
func WithContext ¶
func WithContext(ctx context.Context) ConfigFunc
func WithOnError ¶
func WithOnError(fn func(err error)) ConfigFunc
type Conn ¶
type Conn interface {
Do(ctx context.Context, rb RequestBuilder) (io.ReadCloser, error)
}
Conn is the base connection.
type ConnSession ¶
ConnSession is a connection with a session.
type ErrorType ¶
type ErrorType string
var ( ErrorTypeInvalidSession ErrorType = "InvalidSession" ErrorTypeInvalidRequest ErrorType = "InvalidRequest" ErrorTypeMethodNotFound ErrorType = "MethodNotFound" ErrorTypeInterfaceNotFound ErrorType = "InterfaceNotFound" ErrorTypeNoData ErrorType = "NoData" ErrorTypeUnknown ErrorType = "Unknown" )
type FileClient ¶
type FileClient struct {
// contains filtered or unexported fields
}
FileClient handles file access to prevent "Resource is limited, open video failed!" errors. The client limits the number of concurrent requests and makes sure the body is completely drained.
func NewFileClient ¶
func NewFileClient(client *http.Client, concurrent int) FileClient
func (FileClient) Close ¶
func (c FileClient) Close()
func (FileClient) Do ¶
func (c FileClient) Do(ctx context.Context, urL, cookie string) (io.ReadCloser, error)
type Integer ¶
type Integer int64
Integer is for types that are supposed to be integers but for some reason the device returns a float.
func (*Integer) UnmarshalJSON ¶
type LoginError ¶
type LoginError struct {
Message string
}
func (*LoginError) Error ¶
func (e *LoginError) Error() string
type Request ¶
type Request struct { ID int Session string Method string Params any Object int64 // contains filtered or unexported fields }
func (Request) MarshalJSON ¶
type RequestBuilder ¶
func New ¶
func New(method string) RequestBuilder
func NewLogin ¶
func NewLogin(method string) RequestBuilder
func (RequestBuilder) ID ¶
func (rb RequestBuilder) ID(id int) RequestBuilder
func (RequestBuilder) Object ¶
func (rb RequestBuilder) Object(object int64) RequestBuilder
func (RequestBuilder) Option ¶
func (rb RequestBuilder) Option(key string, value any) RequestBuilder
func (RequestBuilder) Params ¶
func (rb RequestBuilder) Params(params any) RequestBuilder
func (RequestBuilder) Session ¶
func (rb RequestBuilder) Session(session string) RequestBuilder
type Response ¶
type Response[T any] struct { ID int `json:"id"` Session ResponseSession `json:"session"` Error *ResponseError `json:"error"` Params T `json:"params"` Result ResponseResult `json:"result"` }
func FirstLogin ¶
type ResponseError ¶
func (*ResponseError) Error ¶
func (r *ResponseError) Error() string
func (*ResponseError) UnmarshalJSON ¶
func (r *ResponseError) UnmarshalJSON(data []byte) error
type ResponseResult ¶
type ResponseResult int64
func (ResponseResult) Bool ¶
func (s ResponseResult) Bool() bool
func (ResponseResult) Integer ¶
func (s ResponseResult) Integer() int64
func (*ResponseResult) UnmarshalJSON ¶
func (s *ResponseResult) UnmarshalJSON(data []byte) error
type ResponseSession ¶
type ResponseSession string
func (ResponseSession) String ¶
func (s ResponseSession) String() string
func (*ResponseSession) UnmarshalJSON ¶
func (s *ResponseSession) UnmarshalJSON(data []byte) error
type TimeSection ¶
func DefaultTimeSection ¶
func DefaultTimeSection() TimeSection
func NewTimeSectionFromRange ¶
func NewTimeSectionFromRange(number int, start, end time.Time) TimeSection
func NewTimeSectionFromString ¶
func NewTimeSectionFromString(s string) (TimeSection, error)
NewTimeSectionFromString (e.g. "1 08:01:45-16:16:22").
func (TimeSection) MarshalJSON ¶
func (s TimeSection) MarshalJSON() ([]byte, error)
func (TimeSection) String ¶
func (s TimeSection) String() string
func (*TimeSection) UnmarshalJSON ¶
func (s *TimeSection) UnmarshalJSON(data []byte) error