glory kube conn

This commit is contained in:
mr
2025-02-14 11:09:31 +01:00
parent a53dbccc23
commit bff909abbb
15 changed files with 650 additions and 283 deletions

53
controllers/session.go Normal file
View File

@@ -0,0 +1,53 @@
package controllers
import (
"fmt"
"oc-datacenter/infrastructure"
"strconv"
beego "github.com/beego/beego/v2/server/web"
)
type SessionController struct {
beego.Controller
}
// @Title GetToken
// @Description find booking by id
// @Param id path string "id of the datacenter"
// @Param duration path string "duration of the token"
// @Success 200 {booking} models.booking
// @router /token/:id/:duration [get]
func (o *SessionController) GetToken() {
id := o.Ctx.Input.Param(":id")
durationSTR := o.Ctx.Input.Param(":duration")
duration, err := strconv.Atoi(durationSTR)
if err != nil {
// change code to 400
o.Ctx.Output.SetStatus(400)
o.Data["json"] = map[string]string{"error": "duration invalid"}
o.ServeJSON()
return
}
serv, err := infrastructure.NewService()
if err != nil {
// change code to 500
o.Ctx.Output.SetStatus(500)
o.Data["json"] = map[string]string{"error": err.Error()}
o.ServeJSON()
return
}
fmt.Println("BLAPO", id, duration)
token, err := serv.GetToken(o.Ctx.Request.Context(), id, duration)
if err != nil {
// change code to 500
o.Ctx.Output.SetStatus(500)
o.Data["json"] = map[string]string{"error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = token
o.ServeJSON()
}