gdo

package module
v0.0.0-...-b02e13e Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

README

gdo - garage door opener

I'm writing 3 apps for a garage door opener.

gdapi provides a RESTful interface over the door controls and sensors.

gdweb provides an html report and click button

gdmobile if I get it working provides a mobile app experience

Documentation

Overview

Package gdo provides the garage door webserver this file organizes the server oauth2 authentication wrapper and the gdo authorization module

Package gdo provides the garage door webserver this file organizes the door part

Package gdo implements the garage door controller

Package gdo provides the garage door webserver this file organizes the server part

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClickHandler

func ClickHandler(w http.ResponseWriter, r *http.Request)

ClickHandler handles the homepage and anything matching "/api/{owner}/{device}/{state}" Owner = cj or sj Device = ipad, laptop, or all State = lock or unlock

func GetLoggedInUser

func GetLoggedInUser(w http.ResponseWriter, r *http.Request) string

GetLoggedInUser returns the logged in user or cleans up if youve expired

func HomeHandler

func HomeHandler(w http.ResponseWriter, r *http.Request)

HomeHandler handles the homepage and anything matching "/"

func RandomString

func RandomString(n int) string

RandomString produces a base64 string (websafe?) from n random bytes

Types

type AccessEntry

type AccessEntry struct {
	Username string `yaml:"email,omitempty"`
	GoogleID string `yaml:"googleId,omitempty"`
}

AccessEntry populates the access array and allow google id holders to run the services

type ActiveSession

type ActiveSession struct {
	Id      string
	Token   string
	Expires time.Time
}

Sessions track valid tokens

type Config

type Config struct {
	Oauth2  Oauth2Cfg    `yaml:"oauth2"`
	Server  WebserverCfg `yaml:"webserver"`
	Door    DoorCfg      `yaml:"door"`
	Testing bool
}

Config is the gdo config struct. Its members capture config for sections of the program

func GetConfig

func GetConfig() (*Config, error)

GetConfig gets the program config

func NewConfig

func NewConfig(configFileName string) (*Config, error)

NewConfig gets the program config from the specified file

type DoorCfg

type DoorCfg struct {
	ClosedPin        int    `yaml:"closedPin"`
	ClosedValue      bool   `yaml:"closedValue"`
	ClickRelay       int    `yaml:"clickRelay"`
	PiMonitorAddress string `yaml:"pimonitoraddress"`
}

DoorCfg configures the door parameters

type DoorState

type DoorState struct {
	ID        string    `json:"id"`
	State     string    `json:"state"`
	StateTime time.Time `json:"stateTime"`
	Asserted  bool      `json:"asserted,omitempty"`
	Error     string    `json:"error,omitempty"`
}

DoorState is the exposed door data, serializable

type GoogleUserProfile

type GoogleUserProfile struct {
	Email    string `json:"email"`
	Verified bool   `json:"verified_email"`
	ID       string `json:"id"`
	Picture  string `json:"picture"`
}

GoogleUserProfile catches user data

type Oauth2Cfg

type Oauth2Cfg struct {
	ClientSecret string        `yaml:"clientSecret"`
	ClientID     string        `yaml:"clientID"`
	AppName      string        `yaml:"appName"`
	Redirect     string        `yaml:"redirect"`
	Scopes       []string      `yaml:"scopes"`
	Access       []AccessEntry `yaml:"access"`
}

Oauth2Cfg catptures Oauth configs

type OauthLogin

type OauthLogin struct {
	Cookie      http.Cookie
	NextHandler http.Handler
}

OauthLogin type for oauth handler

func NewLoginHandler

func NewLoginHandler(next http.Handler) OauthLogin

NewLoginHandler generates a login middleware

func NewLogoutHandler

func NewLogoutHandler(next http.Handler) OauthLogin

NewLogoutHandler generates a login middleware

func (OauthLogin) ServeHTTP

func (l OauthLogin) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP makes OauthLogin a http.Handler

type Timeout

type Timeout struct {
	Server int `yaml:"server"`
	Write  int `yaml:"write"`
	Read   int `yaml:"read"`
	Idle   int `yaml:"idle"`
}

Timeout captures server timeout settings

type Webserver

type Webserver struct {
	Testing bool
	// contains filtered or unexported fields
}

Webserver is the target object for webserver functions

func NewWebserver

func NewWebserver(cfg *Config) (srv *Webserver, err error)

NewWebserver gets a server ready to go

func (*Webserver) ListenAndServe

func (s *Webserver) ListenAndServe() error

ListenAndServe to implement http.Server

type WebserverCfg

type WebserverCfg struct {
	Host string `yaml:"host"`
	TLS  struct {
		CertFile string `yaml:"cert"`
		KeyFile  string `yaml:"key"`
	} `yaml:"tls"`
	Addr    string  `yaml:"addr"`
	TLSAddr string  `yaml:"tlsAddr"`
	Timeout Timeout `yaml:"timeout"`
}

WebserverCfg captures webserver configs

Directories

Path Synopsis
Code generated for package data by go-bindata DO NOT EDIT.
Code generated for package data by go-bindata DO NOT EDIT.
Code generated for package staticdata by go-bindata DO NOT EDIT.
Code generated for package staticdata by go-bindata DO NOT EDIT.

Jump to

Keyboard shortcuts

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