WIP for API host/port params
This commit is contained in:
parent
5cd894fdcd
commit
189dddc3c0
10
api.go
10
api.go
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
type api struct {
|
||||
master *Master
|
||||
server *martini.ClassicMartini
|
||||
}
|
||||
|
||||
type jsonRobot struct {
|
||||
|
@ -32,14 +33,17 @@ type jsonConnection struct {
|
|||
Adaptor string `json:"adaptor"`
|
||||
}
|
||||
|
||||
var startApi = func(m *martini.ClassicMartini) {
|
||||
go m.Run()
|
||||
func (me *api) StartApi() {
|
||||
go me.server.Run()
|
||||
}
|
||||
|
||||
func Api(bot *Master) *api {
|
||||
a := new(api)
|
||||
a.master = bot
|
||||
bot.Api = a
|
||||
|
||||
m := martini.Classic()
|
||||
a.server = m
|
||||
|
||||
m.Use(martini.Static("robeaux"))
|
||||
|
||||
|
@ -85,7 +89,7 @@ func Api(bot *Master) *api {
|
|||
a.executeCommand(params["robotname"], params["devicename"], params["command"], res, req)
|
||||
})
|
||||
|
||||
startApi(m)
|
||||
//startApi(m)
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package gobot
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/go-martini/martini"
|
||||
//"github.com/go-martini/martini"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"io/ioutil"
|
||||
|
@ -19,8 +19,8 @@ var _ = Describe("Master", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
myMaster = GobotMaster()
|
||||
startApi = func(m *martini.ClassicMartini) {}
|
||||
myMaster = GobotMaster()
|
||||
//startApi = func(m *martini.ClassicMartini) {}
|
||||
a = Api(myMaster)
|
||||
myMaster.Robots = []*Robot{
|
||||
newTestRobot("Robot 1"),
|
||||
|
|
|
@ -12,7 +12,8 @@ func Hello(params map[string]interface{}) string {
|
|||
|
||||
func main() {
|
||||
master := gobot.GobotMaster()
|
||||
gobot.Api(master)
|
||||
api := gobot.Api(master)
|
||||
api.Port = "3000"
|
||||
|
||||
hello := new(gobot.Robot)
|
||||
hello.Name = "hello"
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
type Master struct {
|
||||
Robots []*Robot
|
||||
NumCPU int
|
||||
Api *api
|
||||
}
|
||||
|
||||
func GobotMaster() *Master {
|
||||
|
@ -24,6 +25,10 @@ var trap = func(c chan os.Signal) {
|
|||
func (m *Master) Start() {
|
||||
runtime.GOMAXPROCS(m.NumCPU)
|
||||
|
||||
if m.Api != nil {
|
||||
m.Api.StartApi()
|
||||
}
|
||||
|
||||
for s := range m.Robots {
|
||||
m.Robots[s].startRobot()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue