MCPcopy
hub / github.com/OpenNHP/opennhp / initRouter

Method initRouter

endpoints/server/httpserver.go:204–293  ·  view source on GitHub ↗

init gin engine. Must be called at initialization

()

Source from the content-addressed store, hash-verified

202
203// init gin engine. Must be called at initialization
204func (hs *HttpServer) initRouter() {
205 g := hs.ginEngine
206
207 // load templates. won't trigger panic if file does not exist
208 staticPath := filepath.Join(ExeDirPath, "static")
209 LoadFilesRecursively(g, staticPath)
210 templatePath := filepath.Join(ExeDirPath, "templates")
211 LoadFilesRecursively(g, templatePath)
212
213 pluginGrp := g.Group("plugins")
214 // display login page with templates
215 pluginGrp.GET("/:aspid", func(ctx *gin.Context) {
216 var err error
217 aspId := ctx.Param("aspid")
218 log.Info("get plugins request. aspId: %s, query: %v", aspId, ctx.Request.URL.RawQuery)
219
220 if len(aspId) == 0 {
221 err = common.ErrUrlPathInvalid
222 log.Error("path error: %v", err)
223 ctx.String(http.StatusOK, "{\"errMsg\": \"path error: %v\"}", err)
224 return
225 }
226
227 req := &common.HttpKnockRequest{
228 AuthServiceId: aspId,
229 DeviceId: ctx.Request.UserAgent(),
230 SrcIp: ctx.ClientIP(),
231 Url: ctx.Request.URL,
232 }
233
234 hs.authWithAspPlugin(ctx, req)
235 })
236
237 // legacy api
238 pluginGrp.GET("/:aspid/:resid/valid", func(ctx *gin.Context) {
239 // parse url parameters
240 aspId := ctx.Param("aspid")
241 resId := ctx.Param("resid")
242 log.Info("get plugins request. aspId: %s, resId: %s, query: %v", aspId, resId, ctx.Request.URL.RawQuery)
243
244 if len(aspId) == 0 {
245 log.Error("no aspId provided")
246 ctx.String(http.StatusOK, "{\"errMsg\": \"no aspId provided\"}")
247 return
248 }
249
250 if len(resId) == 0 {
251 log.Error("no resId provided")
252 ctx.String(http.StatusOK, "{\"errMsg\": \"no resId provided\"}")
253 return
254 }
255
256 req := &common.HttpKnockRequest{
257 AuthServiceId: aspId,
258 ResourceId: resId,
259 DeviceId: ctx.Request.UserAgent(),
260 SrcIp: ctx.ClientIP(),
261 Url: ctx.Request.URL,

Callers 1

StartMethod · 0.95

Calls 7

authWithAspPluginMethod · 0.95
initStorageRouterMethod · 0.95
initKbsRouterMethod · 0.95
LoadFilesRecursivelyFunction · 0.85
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected