generate facade service

This commit is contained in:
2025-01-20 21:17:47 +08:00
parent 57b1f544d4
commit 98273c7645
38 changed files with 3307 additions and 1 deletions
+11
View File
@@ -0,0 +1,11 @@
package dal
import (
"github.com/suyiiyii/hertz101/app/facade/biz/dal/mysql"
"github.com/suyiiyii/hertz101/app/facade/biz/dal/redis"
)
func Init() {
redis.Init()
mysql.Init()
}
+24
View File
@@ -0,0 +1,24 @@
package mysql
import (
"github.com/suyiiyii/hertz101/app/facade/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)
}
}
+22
View File
@@ -0,0 +1,22 @@
package redis
import (
"context"
"github.com/redis/go-redis/v9"
"github.com/suyiiyii/hertz101/app/facade/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,9 @@
package facade
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/suyiiyii/hertz101/app/facade/biz/utils"
)
@@ -0,0 +1,10 @@
package facade
import (
"bytes"
"testing"
"github.com/cloudwego/hertz/pkg/app/server"
//"github.com/cloudwego/hertz/pkg/common/test/assert"
"github.com/cloudwego/hertz/pkg/common/ut"
)
+19
View File
@@ -0,0 +1,19 @@
// Code generated by hertz generator. DO NOT EDIT.
package facade
import (
"github.com/cloudwego/hertz/pkg/app/server"
facade "github.com/suyiiyii/hertz101/app/facade/biz/handler/facade"
)
/*
This file will register all the routes of the services in the master idl.
And it will update automatically when you use the "update" command for the idl.
So don't modify the contents of the file, or your code will be deleted when it is updated.
*/
// Register register routes based on the IDL 'api.${HTTP Method}' annotation.
func Register(r *server.Hertz) {
}
@@ -0,0 +1,7 @@
// Code generated by hertz generator.
package facade
import (
"github.com/cloudwego/hertz/pkg/app"
)
+14
View File
@@ -0,0 +1,14 @@
// Code generated by hertz generator. DO NOT EDIT.
package router
import (
"github.com/cloudwego/hertz/pkg/app/server"
facade "github.com/suyiiyii/hertz101/app/facade/biz/router/facade"
)
// GeneratedRegister registers routers generated by IDL.
func GeneratedRegister(r *server.Hertz) {
//INSERT_POINT: DO NOT DELETE THIS LINE!
facade.Register(r)
}
+19
View File
@@ -0,0 +1,19 @@
package utils
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
)
// SendErrResponse pack error response
func SendErrResponse(ctx context.Context, c *app.RequestContext, code int, err error) {
// todo edit custom code
c.String(code, err.Error())
}
// SendSuccessResponse pack success response
func SendSuccessResponse(ctx context.Context, c *app.RequestContext, code int, data interface{}) {
// todo edit custom code
c.JSON(code, data)
}