Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
6c4d1833
Commit
6c4d1833
authored
Jan 29, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust api and debug api routers
parent
fc41140a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
25 deletions
+33
-25
router.go
pkg/api/router.go
+8
-4
router.go
pkg/debugapi/router.go
+25
-21
No files found.
pkg/api/router.go
View file @
6c4d1833
...
...
@@ -17,20 +17,24 @@ import (
)
func
(
s
*
server
)
setupRouting
()
{
baseRouter
:=
mux
.
NewRouter
()
router
:=
mux
.
NewRouter
()
router
.
NotFoundHandler
=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
jsonhttp
.
NotFound
(
w
,
nil
)
})
baseR
outer
.
HandleFunc
(
"/robots.txt"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
r
outer
.
HandleFunc
(
"/robots.txt"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
fmt
.
Fprintln
(
w
,
"User-agent: *
\n
Disallow: /"
)
})
baseR
outer
.
Handle
(
"/pingpong/{peer-id}"
,
jsonhttp
.
MethodHandler
{
r
outer
.
Handle
(
"/pingpong/{peer-id}"
,
jsonhttp
.
MethodHandler
{
"POST"
:
http
.
HandlerFunc
(
s
.
pingpongHandler
),
})
s
.
Handler
=
web
.
ChainHandlers
(
logging
.
NewHTTPAccessLogHandler
(
s
.
Logger
,
logrus
.
InfoLevel
,
"api access"
),
handlers
.
CompressHandler
,
// todo: add recovery handler
s
.
pageviewMetricsHandler
,
web
.
FinalHandler
(
baseR
outer
),
web
.
FinalHandler
(
r
outer
),
)
}
pkg/debugapi/router.go
View file @
6c4d1833
...
...
@@ -19,39 +19,43 @@ import (
)
func
(
s
*
server
)
setupRouting
()
{
internalB
aseRouter
:=
http
.
NewServeMux
()
b
aseRouter
:=
http
.
NewServeMux
()
internalB
aseRouter
.
Handle
(
"/metrics"
,
promhttp
.
InstrumentMetricHandler
(
b
aseRouter
.
Handle
(
"/metrics"
,
promhttp
.
InstrumentMetricHandler
(
s
.
metricsRegistry
,
promhttp
.
HandlerFor
(
s
.
metricsRegistry
,
promhttp
.
HandlerOpts
{}),
))
internalRouter
:=
mux
.
NewRouter
()
internalBaseRouter
.
Handle
(
"/"
,
web
.
ChainHandlers
(
logging
.
NewHTTPAccessLogHandler
(
s
.
Logger
,
logrus
.
InfoLevel
,
"debug api access"
),
handlers
.
CompressHandler
,
web
.
NoCacheHeadersHandler
,
web
.
FinalHandler
(
internalRouter
),
))
internalRouter
.
Handle
(
"/"
,
http
.
NotFoundHandler
())
router
:=
mux
.
NewRouter
()
router
.
NotFoundHandler
=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
jsonhttp
.
NotFound
(
w
,
nil
)
})
internalR
outer
.
Handle
(
"/debug/pprof/"
,
http
.
HandlerFunc
(
pprof
.
Index
))
internalR
outer
.
Handle
(
"/debug/pprof/cmdline"
,
http
.
HandlerFunc
(
pprof
.
Cmdline
))
internalR
outer
.
Handle
(
"/debug/pprof/profile"
,
http
.
HandlerFunc
(
pprof
.
Profile
))
internalR
outer
.
Handle
(
"/debug/pprof/symbol"
,
http
.
HandlerFunc
(
pprof
.
Symbol
))
internalR
outer
.
Handle
(
"/debug/pprof/trace"
,
http
.
HandlerFunc
(
pprof
.
Trace
))
r
outer
.
Handle
(
"/debug/pprof/"
,
http
.
HandlerFunc
(
pprof
.
Index
))
r
outer
.
Handle
(
"/debug/pprof/cmdline"
,
http
.
HandlerFunc
(
pprof
.
Cmdline
))
r
outer
.
Handle
(
"/debug/pprof/profile"
,
http
.
HandlerFunc
(
pprof
.
Profile
))
r
outer
.
Handle
(
"/debug/pprof/symbol"
,
http
.
HandlerFunc
(
pprof
.
Symbol
))
r
outer
.
Handle
(
"/debug/pprof/trace"
,
http
.
HandlerFunc
(
pprof
.
Trace
))
internalR
outer
.
Handle
(
"/debug/vars"
,
expvar
.
Handler
())
r
outer
.
Handle
(
"/debug/vars"
,
expvar
.
Handler
())
internalR
outer
.
HandleFunc
(
"/health"
,
s
.
statusHandler
)
internalR
outer
.
HandleFunc
(
"/readiness"
,
s
.
statusHandler
)
r
outer
.
HandleFunc
(
"/health"
,
s
.
statusHandler
)
r
outer
.
HandleFunc
(
"/readiness"
,
s
.
statusHandler
)
internalR
outer
.
Handle
(
"/connect/{multi-address:.+}"
,
jsonhttp
.
MethodHandler
{
r
outer
.
Handle
(
"/connect/{multi-address:.+}"
,
jsonhttp
.
MethodHandler
{
"POST"
:
http
.
HandlerFunc
(
s
.
peerConnectHandler
),
})
internalR
outer
.
Handle
(
"/peers/{address}"
,
jsonhttp
.
MethodHandler
{
r
outer
.
Handle
(
"/peers/{address}"
,
jsonhttp
.
MethodHandler
{
"DELETE"
:
http
.
HandlerFunc
(
s
.
peerDisconnectHandler
),
})
s
.
Handler
=
internalBaseRouter
baseRouter
.
Handle
(
"/"
,
web
.
ChainHandlers
(
logging
.
NewHTTPAccessLogHandler
(
s
.
Logger
,
logrus
.
InfoLevel
,
"debug api access"
),
handlers
.
CompressHandler
,
// todo: add recovery handler
web
.
NoCacheHeadersHandler
,
web
.
FinalHandler
(
router
),
))
s
.
Handler
=
baseRouter
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment