Skip to content

Commit

Permalink
SSL support in Api
Browse files Browse the repository at this point in the history
  • Loading branch information
deadprogram committed Apr 18, 2014
1 parent ed2bdfb commit 1719a02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

type api struct {
master *Master
server *martini.ClassicMartini
Host string
Port string
Username string
Password string
master *Master
server *martini.ClassicMartini
Host string
Port string
Username string
Password string
Cert string
Key string
}

type jsonRobot struct {
Expand Down Expand Up @@ -51,7 +53,14 @@ var startApi = func(me *api) {
}

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() {
Expand Down
4 changes: 2 additions & 2 deletions master.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Master struct {
Robots []*Robot
NumCPU int
Api *api
Api *api
}

func GobotMaster() *Master {
Expand All @@ -26,7 +26,7 @@ func (m *Master) Start() {
runtime.GOMAXPROCS(m.NumCPU)

if m.Api != nil {
m.Api.StartApi()
m.Api.StartApi()
}

for s := range m.Robots {
Expand Down

0 comments on commit 1719a02

Please sign in to comment.