http

package
v0.0.0-...-11520cc Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActivateAction   = "activate"
	DeactivateAction = "deactivate"
)
View Source
const (
	DailyProgram = "daily"
	OddProgram   = "odd"
	EvenProgram  = "even"
)
View Source
const AuthorizationHeader = "Authorization"

Variables

This section is empty.

Functions

func ActivateDeactivateServer

func ActivateDeactivateServer(ch cqs.CommandHandler) http.HandlerFunc

func AuthMiddleware

func AuthMiddleware(authToken string) func(next http.HandlerFunc) http.HandlerFunc

func CreateProgram

func CreateProgram(ch cqs.CommandHandler, programType string) http.HandlerFunc

func CreateTemperatureProgram

func CreateTemperatureProgram(ch cqs.CommandHandler) http.HandlerFunc

func CreateWeeklyProgram

func CreateWeeklyProgram(ch cqs.CommandHandler) http.HandlerFunc

func CreateZone

func CreateZone(ch cqs.CommandHandler) http.HandlerFunc

func ExecuteZone

func ExecuteZone(ch cqs.CommandHandler) http.HandlerFunc

func FinZones

func FinZones(qh cqs.QueryHandler) http.HandlerFunc

func FindAllPrograms

func FindAllPrograms(qh cqs.QueryHandler) http.HandlerFunc

func FindExecutionLogs

func FindExecutionLogs(qh cqs.QueryHandler) http.HandlerFunc

func FindStatus

func FindStatus(qh cqs.QueryHandler) http.HandlerFunc

func FindWeather

func FindWeather(qh cqs.QueryHandler) http.HandlerFunc

func Homepage

func Homepage() http.HandlerFunc

func NewHandler

func NewHandler(definitions HandlersDefinition) http.Handler

NewHandler is a constructor

func ReadRequest

func ReadRequest(w http.ResponseWriter, r *http.Request, req interface{}) error

func RemoveProgram

func RemoveProgram(ch cqs.CommandHandler, prg string) http.HandlerFunc

func RemoveTemperatureProgram

func RemoveTemperatureProgram(ch cqs.CommandHandler) http.HandlerFunc

func RemoveWeeklyProgram

func RemoveWeeklyProgram(ch cqs.CommandHandler) http.HandlerFunc

func RemoveZone

func RemoveZone(ch cqs.CommandHandler) http.HandlerFunc

func RunServer

func RunServer(ctx context.Context, serverURL string, httpHandler http.Handler, corsOpt *CORSOpt, logger *zerolog.Logger) error

func UpdateTemperatureProgram

func UpdateTemperatureProgram(ch cqs.CommandHandler) http.HandlerFunc

func UpdateZone

func UpdateZone(ch cqs.CommandHandler) http.HandlerFunc

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, statusCode int, errs ...Error)

func WriteResponse

func WriteResponse(w http.ResponseWriter, statusCode int, body []byte)

Types

type CORSOpt

type CORSOpt struct {
	AllowedOrigins     []string
	AllowedMethods     []string
	AllowedHeaders     []string
	OptionsPassthrough bool
}

CORSOpt is a set of CORS options

type CreateProgramRequestJson

type CreateProgramRequestJson struct {
	// Executions corresponds to the JSON schema field "executions".
	Executions []ExecutionRequest `json:"executions" yaml:"executions" mapstructure:"executions"`

	// Hour corresponds to the JSON schema field "hour".
	Hour string `json:"hour" yaml:"hour" mapstructure:"hour"`
}

This schema defines the creation program request

func (*CreateProgramRequestJson) UnmarshalJSON

func (j *CreateProgramRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CreateTemperatureProgramRequestJson

type CreateTemperatureProgramRequestJson struct {
	// Programs corresponds to the JSON schema field "programs".
	Programs []ProgramTemperatureRequest `json:"programs" yaml:"programs" mapstructure:"programs"`

	// Temperature corresponds to the JSON schema field "temperature".
	Temperature float64 `json:"temperature" yaml:"temperature" mapstructure:"temperature"`
}

This schema defines the creation temperature program request

func (*CreateTemperatureProgramRequestJson) UnmarshalJSON

func (j *CreateTemperatureProgramRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CreateWeeklyProgramRequestJson

type CreateWeeklyProgramRequestJson struct {
	// Programs corresponds to the JSON schema field "programs".
	Programs []ProgramWeeklyRequest `json:"programs" yaml:"programs" mapstructure:"programs"`

	// WeekDay corresponds to the JSON schema field "week_day".
	WeekDay string `json:"week_day" yaml:"week_day" mapstructure:"week_day"`
}

This schema defines the creation weekly program request

func (*CreateWeeklyProgramRequestJson) UnmarshalJSON

func (j *CreateWeeklyProgramRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CreateZoneRequestJson

type CreateZoneRequestJson struct {
	// Id corresponds to the JSON schema field "id".
	Id string `json:"id" yaml:"id" mapstructure:"id"`

	// Name corresponds to the JSON schema field "name".
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// Relays corresponds to the JSON schema field "relays".
	Relays []int `json:"relays" yaml:"relays" mapstructure:"relays"`
}

This schema defines the request to create a zone

func (*CreateZoneRequestJson) UnmarshalJSON

func (j *CreateZoneRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Error

type Error struct {
	// Code corresponds to the JSON schema field "code".
	Code ErrorCode `json:"code"`

	// Message corresponds to the JSON schema field "message".
	Message string `json:"message"`
}

type ErrorCode

type ErrorCode string
const ErrorCodeInvalidRequest ErrorCode = "invalid_request"

type ErrorResponseJson

type ErrorResponseJson struct {
	// Errors corresponds to the JSON schema field "errors".
	Errors []Error `json:"errors,omitempty"`
}

type ExecuteZoneRequestJson

type ExecuteZoneRequestJson struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`
}

This schema defines the request to execute a zone

func (*ExecuteZoneRequestJson) UnmarshalJSON

func (j *ExecuteZoneRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ExecutionItemResponse

type ExecutionItemResponse struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// Zones corresponds to the JSON schema field "zones".
	Zones []string `json:"zones" yaml:"zones" mapstructure:"zones"`
}

func (*ExecutionItemResponse) UnmarshalJSON

func (j *ExecutionItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ExecutionLogItemResponse

type ExecutionLogItemResponse struct {
	// ExecutedAt corresponds to the JSON schema field "executed_at".
	ExecutedAt string `json:"executed_at" yaml:"executed_at" mapstructure:"executed_at"`

	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// ZoneName corresponds to the JSON schema field "zone_name".
	ZoneName string `json:"zone_name" yaml:"zone_name" mapstructure:"zone_name"`
}

func (*ExecutionLogItemResponse) UnmarshalJSON

func (j *ExecutionLogItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ExecutionLogsResponseJson

type ExecutionLogsResponseJson []ExecutionLogItemResponse

This schema defines the executions log response

type ExecutionRequest

type ExecutionRequest struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// Zones corresponds to the JSON schema field "zones".
	Zones []string `json:"zones" yaml:"zones" mapstructure:"zones"`
}

func (*ExecutionRequest) UnmarshalJSON

func (j *ExecutionRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ExecutionTemperatureRequest

type ExecutionTemperatureRequest struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// Zones corresponds to the JSON schema field "zones".
	Zones []string `json:"zones" yaml:"zones" mapstructure:"zones"`
}

func (*ExecutionTemperatureRequest) UnmarshalJSON

func (j *ExecutionTemperatureRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ExecutionWeeklyRequest

type ExecutionWeeklyRequest struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// Zones corresponds to the JSON schema field "zones".
	Zones []string `json:"zones" yaml:"zones" mapstructure:"zones"`
}

func (*ExecutionWeeklyRequest) UnmarshalJSON

func (j *ExecutionWeeklyRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type HandlerDefinition

type HandlerDefinition struct {
	Endpoint, Method string
	HandlerFunc      http.HandlerFunc
}

HandlerDefinition used to declare endpoints and http handlers

type HandlersDefinition

type HandlersDefinition []HandlerDefinition

HandlersDefinition is self-described

type ProgramItemResponse

type ProgramItemResponse struct {
	// Executions corresponds to the JSON schema field "executions".
	Executions []ExecutionItemResponse `json:"executions" yaml:"executions" mapstructure:"executions"`

	// Hour corresponds to the JSON schema field "hour".
	Hour string `json:"hour" yaml:"hour" mapstructure:"hour"`
}

func (*ProgramItemResponse) UnmarshalJSON

func (j *ProgramItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ProgramTemperatureRequest

type ProgramTemperatureRequest struct {
	// Executions corresponds to the JSON schema field "executions".
	Executions []ExecutionTemperatureRequest `json:"executions" yaml:"executions" mapstructure:"executions"`

	// Hour corresponds to the JSON schema field "hour".
	Hour string `json:"hour" yaml:"hour" mapstructure:"hour"`
}

func (*ProgramTemperatureRequest) UnmarshalJSON

func (j *ProgramTemperatureRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ProgramWeeklyRequest

type ProgramWeeklyRequest struct {
	// Executions corresponds to the JSON schema field "executions".
	Executions []ExecutionWeeklyRequest `json:"executions" yaml:"executions" mapstructure:"executions"`

	// Hour corresponds to the JSON schema field "hour".
	Hour string `json:"hour" yaml:"hour" mapstructure:"hour"`
}

func (*ProgramWeeklyRequest) UnmarshalJSON

func (j *ProgramWeeklyRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ProgramsResponseJson

type ProgramsResponseJson struct {
	// Daily corresponds to the JSON schema field "daily".
	Daily []ProgramItemResponse `json:"daily" yaml:"daily" mapstructure:"daily"`

	// Even corresponds to the JSON schema field "even".
	Even []ProgramItemResponse `json:"even" yaml:"even" mapstructure:"even"`

	// Odd corresponds to the JSON schema field "odd".
	Odd []ProgramItemResponse `json:"odd" yaml:"odd" mapstructure:"odd"`

	// Temperature corresponds to the JSON schema field "temperature".
	Temperature []TemperatureItemResponse `json:"temperature" yaml:"temperature" mapstructure:"temperature"`

	// Weekly corresponds to the JSON schema field "weekly".
	Weekly []WeeklyItemResponse `json:"weekly" yaml:"weekly" mapstructure:"weekly"`
}

This schema defines the programs response

func (*ProgramsResponseJson) UnmarshalJSON

func (j *ProgramsResponseJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type StatusResponseJson

type StatusResponseJson struct {
	// Active corresponds to the JSON schema field "active".
	Active bool `json:"active" yaml:"active" mapstructure:"active"`

	// Humidity corresponds to the JSON schema field "humidity".
	Humidity float64 `json:"humidity" yaml:"humidity" mapstructure:"humidity"`

	// IsRaining corresponds to the JSON schema field "is_raining".
	IsRaining bool `json:"is_raining" yaml:"is_raining" mapstructure:"is_raining"`

	// SystemStartedAt corresponds to the JSON schema field "system_started_at".
	SystemStartedAt string `json:"system_started_at" yaml:"system_started_at" mapstructure:"system_started_at"`

	// Temperature corresponds to the JSON schema field "temperature".
	Temperature float64 `json:"temperature" yaml:"temperature" mapstructure:"temperature"`

	// UpdatedAt corresponds to the JSON schema field "updated_at".
	UpdatedAt *string `json:"updated_at,omitempty" yaml:"updated_at,omitempty" mapstructure:"updated_at,omitempty"`
}

This schema defines the status response

func (*StatusResponseJson) UnmarshalJSON

func (j *StatusResponseJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type TemperatureItemResponse

type TemperatureItemResponse struct {
	// Programs corresponds to the JSON schema field "programs".
	Programs []ProgramItemResponse `json:"programs" yaml:"programs" mapstructure:"programs"`

	// Temperature corresponds to the JSON schema field "temperature".
	Temperature float64 `json:"temperature" yaml:"temperature" mapstructure:"temperature"`
}

func (*TemperatureItemResponse) UnmarshalJSON

func (j *TemperatureItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type UpdateExecutionTemperatureRequest

type UpdateExecutionTemperatureRequest struct {
	// Seconds corresponds to the JSON schema field "seconds".
	Seconds int `json:"seconds" yaml:"seconds" mapstructure:"seconds"`

	// Zones corresponds to the JSON schema field "zones".
	Zones []string `json:"zones" yaml:"zones" mapstructure:"zones"`
}

func (*UpdateExecutionTemperatureRequest) UnmarshalJSON

func (j *UpdateExecutionTemperatureRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type UpdateProgramTemperatureRequest

type UpdateProgramTemperatureRequest struct {
	// Executions corresponds to the JSON schema field "executions".
	Executions []UpdateExecutionTemperatureRequest `json:"executions" yaml:"executions" mapstructure:"executions"`

	// Hour corresponds to the JSON schema field "hour".
	Hour string `json:"hour" yaml:"hour" mapstructure:"hour"`
}

func (*UpdateProgramTemperatureRequest) UnmarshalJSON

func (j *UpdateProgramTemperatureRequest) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type UpdateTemperatureProgramRequestJson

type UpdateTemperatureProgramRequestJson []UpdateProgramTemperatureRequest

This schema defines update an existing temperature program request

type UpdateZoneRequestJson

type UpdateZoneRequestJson struct {
	// Name corresponds to the JSON schema field "name".
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// Relays corresponds to the JSON schema field "relays".
	Relays []int `json:"relays" yaml:"relays" mapstructure:"relays"`
}

This schema defines the request to update a zone

func (*UpdateZoneRequestJson) UnmarshalJSON

func (j *UpdateZoneRequestJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type WeatherResponseJson

type WeatherResponseJson struct {
	// Humidity corresponds to the JSON schema field "humidity".
	Humidity float64 `json:"humidity" yaml:"humidity" mapstructure:"humidity"`

	// IsRaining corresponds to the JSON schema field "is_raining".
	IsRaining bool `json:"is_raining" yaml:"is_raining" mapstructure:"is_raining"`

	// Temperature corresponds to the JSON schema field "temperature".
	Temperature float64 `json:"temperature" yaml:"temperature" mapstructure:"temperature"`
}

This schema defines the weather response

func (*WeatherResponseJson) UnmarshalJSON

func (j *WeatherResponseJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type WeeklyItemResponse

type WeeklyItemResponse struct {
	// Programs corresponds to the JSON schema field "programs".
	Programs []ProgramItemResponse `json:"programs" yaml:"programs" mapstructure:"programs"`

	// WeekDay corresponds to the JSON schema field "week_day".
	WeekDay string `json:"week_day" yaml:"week_day" mapstructure:"week_day"`
}

func (*WeeklyItemResponse) UnmarshalJSON

func (j *WeeklyItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ZonesItemResponse

type ZonesItemResponse struct {
	// Id corresponds to the JSON schema field "id".
	Id string `json:"id" yaml:"id" mapstructure:"id"`

	// Name corresponds to the JSON schema field "name".
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// Relays corresponds to the JSON schema field "relays".
	Relays []int `json:"relays" yaml:"relays" mapstructure:"relays"`
}

func (*ZonesItemResponse) UnmarshalJSON

func (j *ZonesItemResponse) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ZonesResponseJson

type ZonesResponseJson []ZonesItemResponse

Jump to

Keyboard shortcuts

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