Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0311xuyang committed Dec 4, 2024
1 parent c564597 commit 27b56dc
Show file tree
Hide file tree
Showing 28 changed files with 3,600 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
ports:
- 8000:8000
options: --name dynamo-local
mysql-local:
image: mysql:latest
ports:
- 3306:3306
options: --name mysql-local -e MYSQL_ROOT_PASSWORD=123456
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -25,5 +30,8 @@ jobs:
- name: Wait for DynamoDB Local to start
run: |
while ! nc -z localhost 8000; do sleep 1; done
- name: Wait for MySQL Local to start
run: |
while ! nc -z localhost 3306; do sleep 1; done
- name: Run tests
run: go test -v ./...
30 changes: 30 additions & 0 deletions dal/dal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dal

import (
"sync"

"gorm.io/driver/mysql"
"gorm.io/gorm"
)

var (
// DB is the database connection.
DB *gorm.DB
once sync.Once
)

func init() {
once.Do(func() {
DB = ConnectDB()
})
}

// ConnectDB connects to the database.
func ConnectDB() *gorm.DB {
dsn := "root:123456@tcp(127.0.0.1:3306)/toolkit?charset=utf8mb4&parseTime=True"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
return db
}
Loading

0 comments on commit 27b56dc

Please sign in to comment.