(c *gin.Context)
| 289 | } |
| 290 | |
| 291 | func projectIDInject(c *gin.Context) { |
| 292 | // load project alias |
| 293 | cfg := getConfig(c) |
| 294 | if cfg == nil || len(cfg.Hosts) == 0 { |
| 295 | abortWithError(c, http.StatusInternalServerError, ErrNoPublicServiceHosts) |
| 296 | return |
| 297 | } |
| 298 | |
| 299 | host := c.Request.Host |
| 300 | var ( |
| 301 | p *model.Project |
| 302 | err error |
| 303 | ) |
| 304 | |
| 305 | for _, h := range cfg.Hosts { |
| 306 | if strings.HasSuffix(host, h) { |
| 307 | // treat prefix as string |
| 308 | projectAlias := strings.TrimRight(host[:len(host)-len(h)], ".") |
| 309 | p, err = model.GetProject(model.GetDB(c), projectAlias) |
| 310 | if err == nil { |
| 311 | break |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // try use uri/json/form arguments |
| 317 | if p == nil { |
| 318 | r := struct { |
| 319 | Project string `form:"project" uri:"project" binding:"required,len=64"` |
| 320 | }{} |
| 321 | |
| 322 | _ = c.ShouldBindUri(&r) |
| 323 | |
| 324 | // should not use ShouldBind, json form bind is not repeatable |
| 325 | if err = c.ShouldBindQuery(&r); err != nil { |
| 326 | abortWithError(c, http.StatusBadRequest, err) |
| 327 | return |
| 328 | } |
| 329 | |
| 330 | p, err = model.GetProject(model.GetDB(c), r.Project) |
| 331 | } |
| 332 | |
| 333 | if p != nil { |
| 334 | c.Set("project", p) |
| 335 | } else { |
| 336 | _ = c.Error(err) |
| 337 | abortWithError(c, http.StatusBadRequest, ErrGetProjectFailed) |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | c.Next() |
| 342 | } |
| 343 | |
| 344 | func getUserInfo(c *gin.Context) { |
| 345 | projectDB, err := getCurrentProjectDB(c) |
nothing calls this directly
no test coverage detected