auth service

This commit is contained in:
2025-01-20 16:22:41 +08:00
parent 76d3d6f20a
commit bda2501bae
40 changed files with 3340 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
package dal
import (
"github.com/suyiiyii/hertz101/app/auth/biz/dal/mysql"
)
func Init() {
//redis.Init()
mysql.Init()
}
+33
View File
@@ -0,0 +1,33 @@
package mysql
import (
"fmt"
"github.com/joho/godotenv"
"github.com/suyiiyii/hertz101/app/auth/conf"
"os"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var (
DB *gorm.DB
err error
)
func Init() {
err := godotenv.Load()
if err != nil {
panic(err)
}
dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"), os.Getenv("MYSQL_PORT"))
DB, err = gorm.Open(mysql.Open(dsn),
&gorm.Config{
PrepareStmt: true,
SkipDefaultTransaction: true,
},
)
if err != nil {
panic(err)
}
}
+24
View File
@@ -0,0 +1,24 @@
package redis
import (
"context"
"github.com/redis/go-redis/v9"
"github.com/suyiiyii/hertz101/app/auth/conf"
)
var (
RedisClient *redis.Client
)
func Init() {
RedisClient = redis.NewClient(&redis.Options{
Addr: conf.GetConf().Redis.Address,
Username: conf.GetConf().Redis.Username,
Password: conf.GetConf().Redis.Password,
DB: conf.GetConf().Redis.DB,
})
if err := RedisClient.Ping(context.Background()).Err(); err != nil {
panic(err)
}
}
@@ -0,0 +1,20 @@
package service
import (
"context"
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
)
type DeliverTokenByRPCService struct {
ctx context.Context
} // NewDeliverTokenByRPCService new DeliverTokenByRPCService
func NewDeliverTokenByRPCService(ctx context.Context) *DeliverTokenByRPCService {
return &DeliverTokenByRPCService{ctx: ctx}
}
// Run create note info
func (s *DeliverTokenByRPCService) Run(req *auth.DeliverTokenReq) (resp *auth.DeliveryResp, err error) {
// Finish your business logic.
return
}
@@ -0,0 +1,21 @@
package service
import (
"context"
"testing"
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
)
func TestDeliverTokenByRPC_Run(t *testing.T) {
ctx := context.Background()
s := NewDeliverTokenByRPCService(ctx)
// init req and assert value
req := &auth.DeliverTokenReq{}
resp, err := s.Run(req)
t.Logf("err: %v", err)
t.Logf("resp: %v", resp)
// todo: edit your unit test
}
@@ -0,0 +1,20 @@
package service
import (
"context"
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
)
type VerifyTokenByRPCService struct {
ctx context.Context
} // NewVerifyTokenByRPCService new VerifyTokenByRPCService
func NewVerifyTokenByRPCService(ctx context.Context) *VerifyTokenByRPCService {
return &VerifyTokenByRPCService{ctx: ctx}
}
// Run create note info
func (s *VerifyTokenByRPCService) Run(req *auth.VerifyTokenReq) (resp *auth.VerifyResp, err error) {
// Finish your business logic.
return
}
@@ -0,0 +1,21 @@
package service
import (
"context"
"testing"
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
)
func TestVerifyTokenByRPC_Run(t *testing.T) {
ctx := context.Background()
s := NewVerifyTokenByRPCService(ctx)
// init req and assert value
req := &auth.VerifyTokenReq{}
resp, err := s.Run(req)
t.Logf("err: %v", err)
t.Logf("resp: %v", resp)
// todo: edit your unit test
}