api

package
v0.0.0-...-21b411a Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2014 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package api provides a webserver to interact with your Gobot program over the network.

Example:

package main

import (
	"fmt"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/api"
)

func main() {
	gbot := gobot.NewGobot()

  // Starts the API server on default port 3000
	api.NewAPI(gbot).Start()

  // Accessible via http://localhost:3000/api/commands/say_hello
	gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
		return "Master says hello!"
	})

	hello := gbot.AddRobot(gobot.NewRobot("Eve"))

  // Accessible via http://localhost:3000/robots/Eve/commands/say_hello
	hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
		return fmt.Sprintf("%v says hello!", hello.Name)
	})

	gbot.Start()
}

It follows Common Protocol for Programming Physical Input and Output (CPPP-IO) spec: https://github.com/hybridgroup/cppp-io

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowRequestsFrom

func AllowRequestsFrom(allowedOrigins ...string) http.HandlerFunc

AllowRequestFrom returns handler to verify that requests come from allowedOrigins

func BasicAuth

func BasicAuth(username, password string) http.HandlerFunc

BasicAuth returns basic auth handler.

func NewAPI

func NewAPI(g *gobot.Gobot) *api

newAPI returns a gobot api instance and starts a http server using configuration options

Types

type CORS

type CORS struct {
	AllowOrigins []string
	AllowHeaders []string
	AllowMethods []string
	ContentType  string
	// contains filtered or unexported fields
}

func (*CORS) AllowedHeaders

func (c *CORS) AllowedHeaders() string

AllowedHeaders returns allowed headers in a string

func (*CORS) AllowedMethods

func (c *CORS) AllowedMethods() string

AllowedMethods returns allowed http methods in a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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