Documentation ¶
Overview ¶
Example (Receive) ¶
package main import ( "fmt" sakura "github.com/yamamoto-febc/sakura-iot-go" "net/http" ) func main() { // Listen 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:
Example (Send) ¶
package main import ( sakura "github.com/yamamoto-febc/sakura-iot-go" ) func main() { token := "[put your token]" secret := "[empty or put your secret]" module := "[put your module id]" // create sender sender := sakura.NewWebhookSender(token, secret) // create Payload p := sakura.NewPayload(module) p.AddChannelByInt(0, int32(1)) // ch:0 , set value(int32) p.AddChannelByUint(1, uint32(1)) // ch:1 , set value(uint32) p.AddChannelByInt64(2, int64(1)) // ch:2 , set value(int64) p.AddChannelByUint64(3, uint64(1)) // ch:3 , set value(uint64) p.AddChannelByFloat(4, float32(1)) // ch:4 , set value(float) p.AddChannelByDouble(5, float64(1)) // ch:5 , set value(double) p.AddChannelByHexString(6, "0f1e2d3c4b5c6b7a") // ch:6 , set value(HexString) err := sender.Send(p) if err != nil { panic(err) } }
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)
- func (c *Channel) SetDouble(v float64)
- func (c *Channel) SetFloat(v float32)
- func (c *Channel) SetHexString(v string)
- func (c *Channel) SetInt(v int32)
- func (c *Channel) SetInt64(v int64)
- func (c *Channel) SetUint(v uint32)
- func (c *Channel) SetUint64(v uint64)
- type InnerPayload
- type Payload
- func (p *Payload) AddChannelByDouble(channel int64, value float64)
- func (p *Payload) AddChannelByFloat(channel int64, value float32)
- func (p *Payload) AddChannelByHexString(channel int64, value string)
- func (p *Payload) AddChannelByInt(channel int64, value int32)
- func (p *Payload) AddChannelByInt64(channel int64, value int64)
- func (p *Payload) AddChannelByUint(channel int64, value uint32)
- func (p *Payload) AddChannelByUint64(channel int64, value uint64)
- func (p *Payload) ClearChannels()
- func (p *Payload) IsChannelValue() bool
- func (p *Payload) IsConnection() bool
- func (p *Payload) IsKeepAlive() bool
- type WebhookHandler
- type WebhookHandlerFunc
- type WebhookSender
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PayloadTypesKeepAlive = "keepalive" PayloadTypesChannels = "channels" PayloadTypesConnection = "connection" )
View Source
var WebhookSendRootURL string = "https://api.sakura.io/incoming/v1/"
WebhookSendRootURL is URL prefix of send webhook target
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct { Channel int64 `json:"channel"` Type string `json:"type"` Value interface{} `json:"value"` Datetime *time.Time `json:"datetime,omitempty"` }
func (*Channel) GetHexString ¶
func (*Channel) SetHexString ¶
type InnerPayload ¶
type InnerPayload struct {
Channels []Channel `json:"channels"`
}
type Payload ¶
type Payload struct { Datetime *time.Time `json:"datetime,omitempty"` Module string `json:"module"` Payload InnerPayload `json:"payload"` Type string `json:"type"` }
func NewPayload ¶
func (*Payload) AddChannelByDouble ¶
func (*Payload) AddChannelByFloat ¶
func (*Payload) AddChannelByHexString ¶
func (*Payload) AddChannelByInt ¶
func (*Payload) AddChannelByInt64 ¶
func (*Payload) AddChannelByUint ¶
func (*Payload) AddChannelByUint64 ¶
func (*Payload) ClearChannels ¶
func (p *Payload) ClearChannels()
func (*Payload) IsChannelValue ¶
func (*Payload) IsConnection ¶
func (*Payload) IsKeepAlive ¶
type WebhookHandler ¶
type WebhookHandler struct { // Secret is used to sign payload by HMAC-SHA1 Secret string // HandleFunc is called when received [type = channels] message HandleFunc WebhookHandlerFunc // ConnectedFunc is called when received [type = connection] message ConnectedFunc WebhookHandlerFunc Debug bool }
WebhookHandler is type to handling Webhook that receive from Sakura-IoT-platform
func (*WebhookHandler) ServeHTTP ¶
func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is implements http.Handler interface
type WebhookHandlerFunc ¶
type WebhookHandlerFunc func(Payload)
WebhookHandlerFunc is type of handling request function
type WebhookSender ¶
WebhookSender is type to handling Webhook that send to Sakura-IoT-platform
func NewWebhookSender ¶
func NewWebhookSender(token string, secret string) *WebhookSender
func (*WebhookSender) Send ¶
func (w *WebhookSender) Send(p Payload) error
Click to show internal directories.
Click to hide internal directories.