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:
Ron Evans 2018-08-17 10:32:06 +02:00
parent 6eec38c652
commit 4eb7b17e5a
4 changed files with 12 additions and 9 deletions

View File

@ -107,8 +107,10 @@ func (a *API) Start() {
a.start(a)
}
// StartRaw initializes the api without setting up any routes. Good for custom web interfaces.
func (a *API) StartRaw() {
// StartWithoutDefaults initializes the api without setting up the default routes.
// Good for custom web interfaces.
//
func (a *API) StartWithoutDefaults() {
a.start(a)
}

View File

@ -34,14 +34,14 @@ func initTestAPI() *API {
return a
}
func TestStartRaw(t *testing.T) {
func TestStartWithoutDefaults(t *testing.T) {
log.SetOutput(NullReadWriteCloser{})
g := gobot.NewMaster()
a := NewAPI(g)
a.start = func(m *API) {}
a.Get("/", func(res http.ResponseWriter, req *http.Request) {})
a.StartRaw()
a.StartWithoutDefaults()
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()

View File

@ -26,8 +26,8 @@ func main() {
res.Write([]byte(msg))
})
// starts the API without the "standard" C2PIO API or Robeaux web interface.
a.StartRaw()
// starts the API without the default C2PIO API and Robeaux web interface.
a.StartWithoutDefaults()
master.AddRobot(gobot.NewRobot("hello"))

View File

@ -33,9 +33,10 @@ func main() {
// add the standard C3PIO API routes manually.
a.AddC3PIORoutes()
// starts the API without adding the Robeaux web interface. However, since the C3PIO API was
// already added manually above, that will be available.
a.StartRaw()
// starts the API without the default C2PIO API and Robeaux web interface.
// However, the C3PIO API was added manually using a.AddC3PIORoutes() which
// means the REST API will be available, but not the web interface.
a.StartWithoutDefaults()
hello := master.AddRobot(gobot.NewRobot("hello"))