http

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2022 License: Apache-2.0 Imports: 18 Imported by: 6

Documentation

Overview

Package http implements a http-like hap server to handle requests and responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONDecode added in v1.2.3

func JSONDecode(r io.Reader, v interface{}) error

func JSONEncode added in v1.2.3

func JSONEncode(v interface{}) (*bytes.Buffer, error)

func ReadJSON added in v1.2.3

func ReadJSON(w http.ResponseWriter, r *http.Request, v interface{}) error

func WriteJSON added in v1.2.3

func WriteJSON(w http.ResponseWriter, r *http.Request, v interface{}) error

Types

type CharacteristicRequest added in v1.2.3

type CharacteristicRequest struct {
	AccessoryID      uint64      `json:"aid"`
	CharacteristicID uint64      `json:"iid"`
	Value            interface{} `json:"value"`
	Events           interface{} `json:"ev,omitempty"`
}

type CharacteristicResponse added in v1.2.3

type CharacteristicResponse struct {
	AccessoryID      uint64      `json:"aid"`
	CharacteristicID uint64      `json:"iid"`
	Value            interface{} `json:"value,omitempty"`

	// Status contains the status code. Should be interpreted as integer.
	// The property is omitted if not specified, which makes the payload smaller.
	Status *int `json:"status,omitempty"`
}

type CharacteristicsResponse added in v1.2.3

type CharacteristicsResponse struct {
	Characteristics []CharacteristicResponse `json:"characteristics"`
}

type Config

type Config struct {
	Port      string
	Context   hap.Context
	Database  db.Database
	Container *accessory.Container
	Device    hap.SecuredDevice
	Mutex     *sync.Mutex
	Emitter   event.Emitter
}

type ErrResponse added in v1.2.3

type ErrResponse struct {
	Status int `json:status`
}

ErrResponse is an error response.

type Server

type Server struct {
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c Config) *Server

NewServer returns a server

func (*Server) Accept added in v1.2.3

func (s *Server) Accept() (con net.Conn, err error)

func (*Server) Accessories added in v1.2.3

func (srv *Server) Accessories(w http.ResponseWriter, r *http.Request)

func (*Server) Addr added in v1.2.3

func (s *Server) Addr() net.Addr

func (*Server) Authenticate added in v1.2.3

func (srv *Server) Authenticate(next http.Handler) http.Handler

Authenticate verfies that a sesson for the request is available.

func (*Server) Characteristics added in v1.2.3

func (srv *Server) Characteristics(w http.ResponseWriter, r *http.Request)

Characteristics Handles GET and PUT requests for the /characteristics endpoint.

func (*Server) Close added in v1.2.3

func (s *Server) Close() error

func (*Server) Identify added in v1.2.3

func (srv *Server) Identify(w http.ResponseWriter, r *http.Request)

TODO respond with 400 if accessory is already paired

HTTP/1.1 400 Bad Request
Content-Type: application/hap+json
Content-Length: <length>
{ "status" : -70401 }

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

func (*Server) Port

func (s *Server) Port() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL