Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: merge gorm init with initialisation code #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions docs/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ cwgo 工具支持目前支持生成 MVC Layout,未来还会拓展更多的模

```
├── biz // 业务逻辑目录
│   ├── dal // 数据访问层
│   │   ├── init.go
│   │   ├── mysql
│   │   │   └── init.go
│   │   └── redis
│   │   └── init.go
│   ├── handler // view 层
│   │   └── hello
│   │   └── example
Expand Down Expand Up @@ -48,12 +42,6 @@ RPC 项目目录如下

```
├── biz // 业务逻辑目录
│   ├── dal // 数据访问层
│   │   ├── init.go
│   │   ├── mysql
│   │   │   └── init.go
│   │   └── redis
│   │   └── init.go
│   └── service // service 层,业务逻辑存放的地方。更新时,新的方法会追加文件。
│   ├── HelloMethod.go
│   └── HelloMethod_test.go
Expand Down
78 changes: 0 additions & 78 deletions tpl/hertz/standard/layout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ layouts:
)

func main() {
// init dal
// dal.Init()
address := conf.GetConf().Hertz.Address
h := server.New(server.WithHostPorts(address))

Expand Down Expand Up @@ -292,81 +290,6 @@ layouts:
address: "127.0.0.1:6379"
password: ""


- path: biz/dal/init.go
delims:
- ""
- ""
body: |-
package dal

import (
"{{.GoModule}}/biz/dal/mysql"
"{{.GoModule}}/biz/dal/redis"
)

func Init() {
redis.Init()
mysql.Init()
}

- path: biz/dal/mysql/init.go
delims:
- ""
- ""
body: |-
package mysql

import (
"{{.GoModule}}/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)
}
}


- path: biz/dal/redis/init.go
delims:
- ""
- ""
body: |-
package redis

import (
"context"

"github.com/go-redis/redis/v8"
"{{.GoModule}}/conf"
)

var RedisClient *redis.Client

func Init() {
RedisClient = redis.NewClient(&redis.Options{
Addr: conf.GetConf().Redis.Address,
Password: conf.GetConf().Redis.Password,
})
if err := RedisClient.Ping(context.Background()).Err(); err != nil {
panic(err)
}
}

- path: docker-compose.yaml
delims:
- ""
Expand Down Expand Up @@ -412,7 +335,6 @@ layouts:
| hertz_gen | Hertz generated model |
| biz/handler | Used for request processing, validation and return of response. |
| biz/service | The actual business logic. |
| biz/dal | Logic for operating the storage layer |
| biz/route | Routing and middleware registration |
| biz/utils | Wrapped some common methods |

Expand Down
15 changes: 0 additions & 15 deletions tpl/kitex/server/standard/dal_init.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions tpl/kitex/server/standard/mysql.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tpl/kitex/server/standard/readme_tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ body: |-
| handler.go | Used for request processing return of response. |
| kitex_gen | kitex generated code |
| biz/service | The actual business logic. |
| biz/dal | Logic for operating the storage layer |

## How to run

Expand Down
27 changes: 0 additions & 27 deletions tpl/kitex/server/standard/redis.yaml

This file was deleted.