Documentation
¶
Index ¶
- Constants
- Variables
- func JsonError(res http.ResponseWriter, status int) error
- func JsonMultiStatus(res http.ResponseWriter, body interface{}) error
- func JsonOK(res http.ResponseWriter, body interface{}) error
- func NewChunkedWriter(wr io.Writer, chunk int) io.Writer
- type KeyPair
- type Pairing
- type ServeMux
- type Server
- func (s *Server) DelTimedWrite(request *http.Request)
- func (s *Server) IsAuthorized(request *http.Request) bool
- func (s *Server) IsPaired() bool
- func (s *Server) ListenAndServe(ctx context.Context) error
- func (s *Server) ServeMux() ServeMux
- func (s *Server) SetTimedWrite(ttl, pid uint64, request *http.Request)
- func (s *Server) TimedWrite(request *http.Request) *TimedWrite
- type ServerOption
- type Store
- type TimedWrite
Constants ¶
const ( JsonStatusSuccess = 0 JsonStatusInsufficientPrivileges = -70401 JsonStatusServiceCommunicationFailure = -70402 JsonStatusResourceBusy = -70403 JsonStatusReadOnlyCharacteristic = -70404 JsonStatusWriteOnlyCharacteristic = -70405 JsonStatusNotificationNotSupported = -70406 JsonStatusOutOfResource = -70407 JsonStatusOperationTimedOut = -70408 JsonStatusResourceDoesNotExist = -70409 JsonStatusInvalidValueInRequest = -70410 )
Status codes for json communication.
const ( TlvErrorUnknown = 0x1 TlvErrorInvalidRequest = 0x2 TlvErrorAuthentication = 0x2 TlvErrorBackoff = 0x3 TlvErrorMaxPeers = 0x4 TlvErrorUnknownPeer = 0x4 TlvErrorMaxTries = 0x5 TlvErrorBusy = 0x7 )
Error codes for TLV8 communication.
const ( // HTTPContentTypePairingTLV8 is the HTTP content type for tlv8 data HTTPContentTypePairingTLV8 = "application/pairing+tlv8" // HTTPContentTypeHAPJson is the HTTP content type for json data HTTPContentTypeHAPJson = "application/hap+json" )
const ( MethodPair byte = 0x0 // pair MethodPairMFi byte = 0x1 // MFi compliant accessory MethodVerifyPair byte = 0x2 // verify a pairing MethodAddPairing byte = 0x3 // add client through secure connection MethodDeletePairing byte = 0x4 // delete pairing through secure connection MethodListPairings byte = 0x5 )
const ( // PermissionUser is the user permission for a paired controller. PermissionUser byte = 0x0 // PermissionAdmin is the administrator permission for a paired controller. PermissionAdmin byte = 0x1 )
Variables ¶
Functions ¶
func JsonError ¶
func JsonError(res http.ResponseWriter, status int) error
JsonErrors sends an HTTP 500 (bad request) response including the status in the body.
func JsonMultiStatus ¶
func JsonMultiStatus(res http.ResponseWriter, body interface{}) error
JsonMultiStatus sends an HTTP 207 (multi status) response.
func JsonOK ¶
func JsonOK(res http.ResponseWriter, body interface{}) error
JsonOK sends an HTTP 200 (ok) response.
Types ¶
type ServeMux ¶
type ServeMux interface {
// Handle registers the handler for the given pattern.
Handle(pattern string, handler http.Handler)
// HandleFunc registers the handler function for the given pattern.
HandleFunc(pattern string, handler http.HandlerFunc)
// Mount attaches another http.Handler along ./pattern/*
Mount(pattern string, handler http.Handler)
}
A ServeMux lets you attach handlers to http url paths.
type Server ¶
type Server struct {
// Pin specifies the pincode used to pair
// with the accessory.
Pin string
// Addr specifies the tcp address for the server
// to listen to in form of "host:port".
// If empty, a random port is used.
Addr string
// Ifaces specifies at which interface the
// associated dnssd service is announced.
Ifaces []string
MfiCompliant bool // default false
Protocol string // default "1.0"
SetupId string
Key KeyPair // public and private key (generated and stored on disk)
// contains filtered or unexported fields
}
A server handles incoming HTTP request for an accessory. The server uses dnssd to announce the accessory on the local network.
func NewServer ¶
NewServer returns a new server given a store (to persist data) and accessories. If more than one accessory is added to the server, *a* acts as a bridge. The compatibility constructor uses a discard-backed logger; use NewServerWithOptions and WithLogger to receive structured records.
func NewServerWithOptions ¶
NewServerWithOptions returns a new server configured with options.
func (*Server) DelTimedWrite ¶
func (*Server) IsAuthorized ¶
IsAuthorized returns true if the provided request is authorized to access accessory data.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server.
func (*Server) SetTimedWrite ¶
func (*Server) TimedWrite ¶
func (s *Server) TimedWrite(request *http.Request) *TimedWrite
type ServerOption ¶
type ServerOption func(*serverOptions)
ServerOption configures a Server created by NewServerWithOptions.
func WithBridgedAccessories ¶
func WithBridgedAccessories(accessories ...*accessory.A) ServerOption
WithBridgedAccessories adds accessories behind the primary bridge accessory.
func WithLogger ¶
func WithLogger(logger *slog.Logger) ServerOption
WithLogger configures the server to emit structured records through logger. The logger and its handler remain owned by the caller, allowing handlers that redact or otherwise transform attributes before they are written.
type Store ¶
type Store interface {
// Set sets the value for the given key.
Set(key string, value []byte) error
// Get returns the value for the given key. If the key does not exist,
// the returned error must satisfy errors.Is(err, io/fs.ErrNotExist).
Get(key string) ([]byte, error)
// Delete deletes the value for the given key. If the key does not exist,
// the returned error must satisfy errors.Is(err, io/fs.ErrNotExist).
Delete(key string) error
// KeysWithSuffix returns a list keys with the give suffix.
KeysWithSuffix(suffix string) ([]string, error)
}
A Store lets you store key-value pairs.
func NewFsStore ¶
func NewMemStore ¶
func NewMemStore() Store
type TimedWrite ¶
type TimedWrite struct {
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
THIS FILE IS AUTO-GENERATED
|
THIS FILE IS AUTO-GENERATED |
|
Package characteristic implements the HomeKit characteristics.
|
Package characteristic implements the HomeKit characteristics. |
|
cmd
|
|
|
bridge
command
|
|
|
switch
command
This example show an example of a switch accessory which periodically changes it's state between on and off.
|
This example show an example of a switch accessory which periodically changes it's state between on and off. |
|
THIS FILE IS AUTO-GENERATED
|
THIS FILE IS AUTO-GENERATED |