fix: 删除测试代码

main
熊二 1 year ago
parent 95ed5bbdd4
commit bf3833ad95
  1. 38
      internal/init.go

@ -2,17 +2,15 @@ package internal
import ( import (
"errors" "errors"
"fmt"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"gorm.io/gorm"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/middleware" "sorbet/internal/middleware"
"sorbet/internal/repositories"
"sorbet/internal/util" "sorbet/internal/util"
"sorbet/pkg/db" "sorbet/pkg/db"
"sorbet/pkg/env" "sorbet/pkg/env"
"sorbet/pkg/log" "sorbet/pkg/log"
"sorbet/pkg/rsp" "sorbet/pkg/rsp"
"sorbet/pkg/ticket"
) )
func Init() error { func Init() error {
@ -61,31 +59,13 @@ func Start() error {
e.Use(middleware.Recover()) e.Use(middleware.Recover())
e.Use(middleware.CORS()) e.Use(middleware.CORS())
e.Use(middleware.Logger) e.Use(middleware.Logger)
e.GET("/", func(c echo.Context) error { return run(e)
repo := repositories.NewCompanyRepository(c.Get("db").(*gorm.DB)) }
company, err := repo.GetByID(c.Request().Context(), 1)
if err != nil { func run(e *echo.Echo) error {
return err port := env.String("SERVER_PORT", "1324")
} addr := fmt.Sprintf(":%s", port)
token, err := ticket.Create(&ticket.Claims{ // TODO(hupeh): 验证 addr 是否合法
UID: company.ID, e.Logger.Fatal(e.Start(addr))
Role: "system",
Issuer: "chshs",
Subject: "subject",
})
if err != nil {
return err
}
return rsp.Ok(c, echo.Map{
"token": token,
})
})
e.Group("", ticket.Middleware(false, "system")).GET("/u", func(c echo.Context) error {
return rsp.Ok(c, echo.Map{
"ticket": c.Get("ticket"),
"claims": c.Get("ticket_claims").(*ticket.Claims),
})
})
e.Logger.Fatal(e.Start(":1323"))
return nil return nil
} }

Loading…
Cancel
Save