Feat: finish login and add test
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"gitea.konchin.com/go2025/backend/implements"
|
||||
"gitea.konchin.com/go2025/backend/middlewares"
|
||||
"gitea.konchin.com/go2025/backend/tracing"
|
||||
"gitea.konchin.com/go2025/backend/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
"github.com/uptrace/bun/extra/bunotel"
|
||||
"github.com/uptrace/bunrouter"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.uber.org/zap"
|
||||
|
||||
_ "gitea.konchin.com/go2025/backend/docs"
|
||||
)
|
||||
@@ -48,6 +50,13 @@ var serveCmd = &cobra.Command{
|
||||
bunDB := bun.NewDB(sqldb, pgdialect.New())
|
||||
bunDB.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("backend")))
|
||||
|
||||
if err := utils.InitDB(ctx, bunDB); err != nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Panic("failed to init database",
|
||||
zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
/*
|
||||
// Initialize MinIO instance
|
||||
mc, err := minio.New(viper.GetString("minio-host"), &minio.Options{
|
||||
@@ -97,6 +106,7 @@ var serveCmd = &cobra.Command{
|
||||
|
||||
authGroup := backend.NewGroup("/auth")
|
||||
authGroup.POST("/login", auths.PostLogin)
|
||||
authGroup.POST("/gen-login-url", auths.PostGenLoginUrl)
|
||||
|
||||
if viper.GetBool("swagger") {
|
||||
backend.GET("/swagger/*any",
|
||||
@@ -113,6 +123,8 @@ var serveCmd = &cobra.Command{
|
||||
func init() {
|
||||
serveCmd.Flags().
|
||||
String("port", "8080", "Port to listen on")
|
||||
serveCmd.Flags().
|
||||
String("external-url", "http://localhost:8080", "External url for login")
|
||||
serveCmd.Flags().
|
||||
String("cors-origin", "", "CORS origin")
|
||||
|
||||
@@ -132,7 +144,7 @@ func init() {
|
||||
|
||||
serveCmd.Flags().
|
||||
String("pg-connection-string",
|
||||
"postgres://go2025:go2025@pg:5432/go2025?sslmode=disable",
|
||||
"postgres://go2025:go2025@postgres:5432/go2025?sslmode=disable",
|
||||
"Postgres connection string")
|
||||
|
||||
serveCmd.Flags().
|
||||
|
||||
Reference in New Issue
Block a user