-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added global database management features and optimized the user authentication process #2
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e89113
feat: Added global database management features and optimized the use…
GT-610 4b97e7c
refactor(network): Refactor the network service to support dynamic da…
GT-610 e62feb5
fix (Network Service): Add a mutex to protect database connection ope…
GT-610 4f8d321
fix: Added a check for the ZeroTier client and fixed error handling f…
GT-610 1e6e429
fix(database): Close the database connection if initialization fails
GT-610 154e700
fix(database): Close old connections and fix indentation before setti…
GT-610 6c13959
fix (Database): Fixed an issue where connections were not closed duri…
GT-610 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ name: Docker | |
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## Build instructions | ||
| 1. Go Build binary should be in `./build` folder. DON'T BUILD ELSEWHERE. | ||
| 2. NPM has hot reload, no need to rerun to see changes in real-time | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| "github.com/GT-610/tairitsu/internal/app/logger" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| var ( | ||
| globalDB DBInterface | ||
| globalDBMu sync.RWMutex | ||
| ) | ||
|
|
||
| // SetGlobalDB sets the global database instance | ||
| func SetGlobalDB(db DBInterface) { | ||
| globalDBMu.Lock() | ||
| defer globalDBMu.Unlock() | ||
| if globalDB != nil { | ||
| globalDB.Close() | ||
| logger.Info("已关闭旧的数据库连接") | ||
| } | ||
| globalDB = db | ||
| logger.Info("全局数据库实例已设置") | ||
| } | ||
|
|
||
| // GetGlobalDB returns the global database instance | ||
| func GetGlobalDB() DBInterface { | ||
| globalDBMu.RLock() | ||
| defer globalDBMu.RUnlock() | ||
| return globalDB | ||
| } | ||
|
|
||
| // InitGlobalDB initializes the global database from config | ||
| func InitGlobalDB() error { | ||
| globalDBMu.Lock() | ||
| defer globalDBMu.Unlock() | ||
|
|
||
| config := LoadConfig() | ||
| if config.Type == "" { | ||
| logger.Warn("数据库配置为空,跳过全局数据库初始化") | ||
| return nil | ||
| } | ||
|
|
||
| db, err := NewDatabase(config) | ||
| if err != nil { | ||
| logger.Error("创建数据库实例失败", zap.Error(err)) | ||
| return err | ||
| } | ||
|
|
||
| if err := db.Init(); err != nil { | ||
| logger.Error("初始化数据库失败", zap.Error(err)) | ||
| db.Close() | ||
| return err | ||
| } | ||
|
|
||
| if globalDB != nil { | ||
| globalDB.Close() | ||
| logger.Info("已关闭旧的数据库连接") | ||
| } | ||
| globalDB = db | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| logger.Info("全局数据库初始化成功", zap.String("type", string(config.Type))) | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.