Documentation
¶
Overview ¶
Package dahuarpc is a client library for Dahua's RPC API.
Index ¶
- Constants
- 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 Error
- type ErrorType
- type FileClient
- type FileResponse
- type Integer
- 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 ResponseResult
- type ResponseSession
- type State
- type TimeSection
- type Timestamp
Constants ¶
const ( LoginMessageUserOrPasswordNotValid = "User or password not valid" LoginMessageUserNotValid = "User not valid" LoginMessagePasswordNotValid = "Password not valid" LoginMessageInBlackList = "User in blackList" LoginMessageHasBeedUsed = "User has be used" LoginMessageHasBeenLocked = "User locked" )
Variables ¶
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 NewClient ¶
func NewClient(ip, username, password string, configFuncs ...ConfigFunc) Client
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 WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ConfigFunc
func WithOnError ¶
func WithOnError(fn func(err error)) ConfigFunc
func WithURL ¶
func WithURL(rpcURL, rpcLoginURL string) 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 Error ¶
func (*Error) UnmarshalJSON ¶
type ErrorType ¶
type ErrorType string
var ( ErrorTypeInvalidLogin ErrorType = "InvalidLogin" 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) (FileResponse, error)
type FileResponse ¶
type FileResponse struct { io.ReadCloser ContentLength int64 // contains filtered or unexported fields }
func (FileResponse) Close ¶
func (r FileResponse) Close() 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 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 *Error `json:"error"` Params T `json:"params"` Result ResponseResult `json:"result"` }
func FirstLogin ¶
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