1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

SSL support in Api

This commit is contained in:
deadprogram 2014-04-18 16:04:49 -07:00
parent ed2bdfb510
commit 1719a02370
2 changed files with 18 additions and 9 deletions

23
api.go
View File

@ -10,12 +10,14 @@ import (
) )
type api struct { type api struct {
master *Master master *Master
server *martini.ClassicMartini server *martini.ClassicMartini
Host string Host string
Port string Port string
Username string Username string
Password string Password string
Cert string
Key string
} }
type jsonRobot struct { type jsonRobot struct {
@ -51,7 +53,14 @@ var startApi = func(me *api) {
} }
host := me.Host host := me.Host
go http.ListenAndServe(host+":"+port, me.server) cert := me.Cert
key := me.Key
if cert != "" && key != "" {
go http.ListenAndServeTLS(host+":"+port, cert, key, me.server)
} else {
go http.ListenAndServe(host+":"+port, me.server)
}
} }
func (me *api) StartApi() { func (me *api) StartApi() {

View File

@ -9,7 +9,7 @@ import (
type Master struct { type Master struct {
Robots []*Robot Robots []*Robot
NumCPU int NumCPU int
Api *api Api *api
} }
func GobotMaster() *Master { func GobotMaster() *Master {
@ -26,7 +26,7 @@ func (m *Master) Start() {
runtime.GOMAXPROCS(m.NumCPU) runtime.GOMAXPROCS(m.NumCPU)
if m.Api != nil { if m.Api != nil {
m.Api.StartApi() m.Api.StartApi()
} }
for s := range m.Robots { for s := range m.Robots {