api: settled on StartWithoutDefaults() as the method to start API without default routes
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
6eec38c652
commit
4eb7b17e5a
|
@ -107,8 +107,10 @@ func (a *API) Start() {
|
||||||
a.start(a)
|
a.start(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartRaw initializes the api without setting up any routes. Good for custom web interfaces.
|
// StartWithoutDefaults initializes the api without setting up the default routes.
|
||||||
func (a *API) StartRaw() {
|
// Good for custom web interfaces.
|
||||||
|
//
|
||||||
|
func (a *API) StartWithoutDefaults() {
|
||||||
a.start(a)
|
a.start(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,14 @@ func initTestAPI() *API {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartRaw(t *testing.T) {
|
func TestStartWithoutDefaults(t *testing.T) {
|
||||||
log.SetOutput(NullReadWriteCloser{})
|
log.SetOutput(NullReadWriteCloser{})
|
||||||
g := gobot.NewMaster()
|
g := gobot.NewMaster()
|
||||||
a := NewAPI(g)
|
a := NewAPI(g)
|
||||||
a.start = func(m *API) {}
|
a.start = func(m *API) {}
|
||||||
|
|
||||||
a.Get("/", func(res http.ResponseWriter, req *http.Request) {})
|
a.Get("/", func(res http.ResponseWriter, req *http.Request) {})
|
||||||
a.StartRaw()
|
a.StartWithoutDefaults()
|
||||||
|
|
||||||
request, _ := http.NewRequest("GET", "/", nil)
|
request, _ := http.NewRequest("GET", "/", nil)
|
||||||
response := httptest.NewRecorder()
|
response := httptest.NewRecorder()
|
||||||
|
|
|
@ -26,8 +26,8 @@ func main() {
|
||||||
res.Write([]byte(msg))
|
res.Write([]byte(msg))
|
||||||
})
|
})
|
||||||
|
|
||||||
// starts the API without the "standard" C2PIO API or Robeaux web interface.
|
// starts the API without the default C2PIO API and Robeaux web interface.
|
||||||
a.StartRaw()
|
a.StartWithoutDefaults()
|
||||||
|
|
||||||
master.AddRobot(gobot.NewRobot("hello"))
|
master.AddRobot(gobot.NewRobot("hello"))
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,10 @@ func main() {
|
||||||
// add the standard C3PIO API routes manually.
|
// add the standard C3PIO API routes manually.
|
||||||
a.AddC3PIORoutes()
|
a.AddC3PIORoutes()
|
||||||
|
|
||||||
// starts the API without adding the Robeaux web interface. However, since the C3PIO API was
|
// starts the API without the default C2PIO API and Robeaux web interface.
|
||||||
// already added manually above, that will be available.
|
// However, the C3PIO API was added manually using a.AddC3PIORoutes() which
|
||||||
a.StartRaw()
|
// means the REST API will be available, but not the web interface.
|
||||||
|
a.StartWithoutDefaults()
|
||||||
|
|
||||||
hello := master.AddRobot(gobot.NewRobot("hello"))
|
hello := master.AddRobot(gobot.NewRobot("hello"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue