Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" sakura "github.com/yamamoto-febc/sakura-iot-go" "net/http" ) func main() { http.Handle("/", &sakura.WebhookHandler{ Secret: "[put your secret]", HandleFunc: func(p sakura.Payload) { // [ここにWebhook 受信時の処理を書く] fmt.Printf("Module:%s\n", p.Module) fmt.Printf("Type :%s\n", p.Type) fmt.Printf("Channels:%#v\n", p.Payload.Channels) }, }) http.ListenAndServe(":8080", nil) }
Output:
Index ¶
- Variables
- type Channel
- func (c *Channel) GetDouble() (float64, error)
- func (c *Channel) GetFloat() (float32, error)
- func (c *Channel) GetHexString() (string, error)
- func (c *Channel) GetInt() (int32, error)
- func (c *Channel) GetInt64() (int64, error)
- func (c *Channel) GetUint() (uint32, error)
- func (c *Channel) GetUint64() (uint64, error)
- type InnerPayload
- type Payload
- type WebhookHandler
- type WebhookHandlerFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PayloadTypesKeepAlive = "keepalive" PayloadTypesChannels = "channels" )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct { Channel int64 `json:"channel"` Type string `json:"type"` Value interface{} `json:"value"` }
func (*Channel) GetHexString ¶
type InnerPayload ¶
type InnerPayload struct {
Channels []Channel `json:"channels"`
}
type Payload ¶
type Payload struct { Datetime time.Time `json:"datetime"` Module string `json:"module"` Payload InnerPayload `json:"payload"` Type string `json:"type"` }
func (*Payload) IsChannelValue ¶
func (*Payload) IsKeepAlive ¶
type WebhookHandler ¶
type WebhookHandler struct { Secret string HandleFunc WebhookHandlerFunc Debug bool }
func (*WebhookHandler) ServeHTTP ¶
func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type WebhookHandlerFunc ¶
type WebhookHandlerFunc func(Payload)
Click to show internal directories.
Click to hide internal directories.