This commit is contained in:
2025-01-17 17:09:32 +08:00
commit d696206dc7
40 changed files with 2357 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
package dal
import (
"github.com/suyiiyii/hertz101/app/user/biz/dal/mysql"
"github.com/suyiiyii/hertz101/app/user/biz/dal/redis"
)
func Init() {
redis.Init()
mysql.Init()
}
+25
View File
@@ -0,0 +1,25 @@
package mysql
import (
"github.com/suyiiyii/hertz101/app/user/conf"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var (
DB *gorm.DB
err error
)
func Init() {
DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.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/user/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)
}
}
+20
View File
@@ -0,0 +1,20 @@
package service
import (
"context"
user "github.com/suyiiyii/hertz101/rpc_gen/kitex_gen/user"
)
type LoginService struct {
ctx context.Context
} // NewLoginService new LoginService
func NewLoginService(ctx context.Context) *LoginService {
return &LoginService{ctx: ctx}
}
// Run create note info
func (s *LoginService) Run(req *user.LoginReq) (resp *user.LoginResp, err error) {
// Finish your business logic.
return
}
+21
View File
@@ -0,0 +1,21 @@
package service
import (
"context"
"testing"
user "github.com/suyiiyii/hertz101/rpc_gen/kitex_gen/user"
)
func TestLogin_Run(t *testing.T) {
ctx := context.Background()
s := NewLoginService(ctx)
// init req and assert value
req := &user.LoginReq{}
resp, err := s.Run(req)
t.Logf("err: %v", err)
t.Logf("resp: %v", resp)
// todo: edit your unit test
}
+20
View File
@@ -0,0 +1,20 @@
package service
import (
"context"
user "github.com/suyiiyii/hertz101/rpc_gen/kitex_gen/user"
)
type RegisterService struct {
ctx context.Context
} // NewRegisterService new RegisterService
func NewRegisterService(ctx context.Context) *RegisterService {
return &RegisterService{ctx: ctx}
}
// Run create note info
func (s *RegisterService) Run(req *user.RegisterResp) (resp *user.RegisterResp, err error) {
// Finish your business logic.
return
}
+21
View File
@@ -0,0 +1,21 @@
package service
import (
"context"
"testing"
user "github.com/suyiiyii/hertz101/rpc_gen/kitex_gen/user"
)
func TestRegister_Run(t *testing.T) {
ctx := context.Background()
s := NewRegisterService(ctx)
// init req and assert value
req := &user.RegisterResp{}
resp, err := s.Run(req)
t.Logf("err: %v", err)
t.Logf("resp: %v", resp)
// todo: edit your unit test
}