Skip to content

Commit

Permalink
doc route
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Aug 13, 2018
1 parent 756f467 commit f7a59c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
32 changes: 6 additions & 26 deletions app.go
Expand Up @@ -22,10 +22,6 @@ package pitaya

import (
"context"
ejson "encoding/json"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"reflect"
Expand Down Expand Up @@ -164,8 +160,6 @@ func configureMetrics(serverType string) {
AddMetricsReporter(metricsReporter)
}
}

exposeHandlersDoc()
}

// AddAcceptor adds a new acceptor to app
Expand Down Expand Up @@ -501,24 +495,10 @@ func ExtractSpan(ctx context.Context) (opentracing.SpanContext, error) {
return tracing.ExtractSpan(ctx)
}

func exposeHandlersDoc() {
http.HandleFunc("/docs", func(w http.ResponseWriter, r *http.Request) {
docs := map[string]interface{}{
"handlers": handlerService.Docs(),
"remotes": remoteService.Docs(),
}
bts, err := ejson.Marshal(docs)
if err != nil {
logger.Log.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
}

w.Write(bts)
})

// TODO: tem que iniciar uma unica vez
go (func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", 8082), nil))
})()
// Documentation returns handler and remotes documentacion
func Documentation() map[string]interface{} {
return map[string]interface{}{
"handlers": handlerService.Docs(),
"remotes": remoteService.Docs(),
}
}
2 changes: 1 addition & 1 deletion service/handler.go
Expand Up @@ -318,7 +318,7 @@ func (h *HandlerService) DumpServices() {
}
}

// Docs ...
// Docs returns documentation for handlers
func (h *HandlerService) Docs() map[string]interface{} {
return docgenerator.HandlersDocs(h.server.Type, h.services)
}
2 changes: 1 addition & 1 deletion service/remote.go
Expand Up @@ -430,7 +430,7 @@ func (r *RemoteService) DumpServices() {
}
}

// Docs ...
// Docs returns documentation for remotes
func (r *RemoteService) Docs() map[string]interface{} {
return docgenerator.RemotesDocs(r.server.Type, r.services)
}

0 comments on commit f7a59c5

Please sign in to comment.