init gin engine. Must be called at initialization
()
| 202 | |
| 203 | // init gin engine. Must be called at initialization |
| 204 | func (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, |
no test coverage detected