62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
"io/fs"
|
|
m "k8s-manager/src"
|
|
"net/http"
|
|
)
|
|
|
|
//go:embed template/* static/*
|
|
var f embed.FS
|
|
|
|
func main() {
|
|
m.InitClient()
|
|
|
|
r := gin.Default()
|
|
|
|
fp, _ := fs.Sub(f, "static")
|
|
r.StaticFS("/static", http.FS(fp))
|
|
|
|
r.GET("/index", m.JWTAuthMiddleware, func(c *gin.Context) {
|
|
c.FileFromFS("/template/app_view.html", http.FS(f))
|
|
})
|
|
r.GET("/apps", m.JWTAuthMiddleware, m.GetAppsController)
|
|
r.POST("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
|
r.PUT("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
|
r.DELETE("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
|
|
|
r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
|
|
r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
|
|
|
|
r.GET("/login/:username", Test)
|
|
r.GET("/username", m.JWTAuthMiddleware, m.GetUsername)
|
|
err := r.Run(":8000")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func Test(c *gin.Context) {
|
|
username := c.Param("username")
|
|
if username == "" {
|
|
c.JSON(http.StatusNotFound, gin.H{
|
|
"code": http.StatusNotFound,
|
|
"msg": "No user name.",
|
|
})
|
|
} else {
|
|
token, err := m.GenerateToken(username)
|
|
if err != nil {
|
|
log.Error(err)
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.SetCookie("Authorization", "Bearer "+token, 0, "", "", false, false)
|
|
c.Header("Authorization", "Bearer "+token)
|
|
c.Header("Cache-Control", "no-store")
|
|
c.Redirect(http.StatusTemporaryRedirect, "/index")
|
|
}
|
|
}
|