创建表

This commit is contained in:
zhangkun9038@dingtalk.com 2025-02-16 21:51:52 +08:00
parent d550187616
commit 9170785784
5 changed files with 7 additions and 41 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
vendor/ vendor/
rbac

View File

@ -23,6 +23,7 @@ type Config struct {
RedisHost string RedisHost string
RedisPort int RedisPort int
RedisPassword string RedisPassword string
RedisDB int
} }
var AppConfig Config var AppConfig Config
@ -30,16 +31,17 @@ var AppConfig Config
func Init() { func Init() {
AppConfig = Config{ AppConfig = Config{
DB: DBConfig{ DB: DBConfig{
Host: getEnv("DB_HOST", "localhost"), Host: getEnv("DB_HOST", "192.168.65.5"),
Port: getEnvAsInt("DB_PORT", 3306), Port: getEnvAsInt("DB_PORT", 3306),
User: getEnv("DB_USER", "root"), User: getEnv("DB_USER", "root"),
Password: getEnv("DB_PASSWORD", ""), Password: getEnv("DB_PASSWORD", "d8db*#00oS"),
Name: getEnv("DB_NAME", "rbac"), Name: getEnv("DB_NAME", "rbac"),
}, },
JWTSecret: getEnv("JWT_SECRET", "secret"), JWTSecret: getEnv("JWT_SECRET", "secret"),
RedisHost: getEnv("REDIS_HOST", "localhost"), RedisHost: getEnv("REDIS_HOST", "192.168.65.5"),
RedisPort: getEnvAsInt("REDIS_PORT", 6379), RedisPort: getEnvAsInt("REDIS_PORT", 6379),
RedisPassword: getEnv("REDIS_PASSWORD", ""), RedisPassword: getEnv("REDIS_PASSWORD", ""),
RedisDB: getEnvAsInt("REDIS_DB", 2),
} }
} }

37
main.go
View File

@ -1,4 +1,3 @@
<<<<<<< HEAD
package main package main
import ( import (
@ -14,39 +13,3 @@ func main() {
api.SetupRoutes(r) api.SetupRoutes(r)
r.Run(":8080") r.Run(":8080")
} }
=======
package main
import (
"gitea.zjmud.xyz/phyer/rbac/api"
"gitea.zjmud.xyz/phyer/rbac/config"
"gitea.zjmud.xyz/phyer/rbac/server"
)
func main() {
config.Init()
server.InitDB()
r := server.NewServer()
api.SetupRoutes(r)
r.Run(":8080")
}
>>>>>>> Snippet
// package main
//
// import (
// "gitea.zjmud.xyz/phyer/rbac/config"
// "gitea.zjmud.xyz/phyer/rbac/server"
// "gitea.zjmud.xyz/phyer/rbac/utils"
// )
//
// func main() {
// // 初始化配置
// config.Init()
//
// // 初始化 Redis
// utils.InitRedis()
//
// // 启动服务器
// server.Start()
// }

BIN
rbac

Binary file not shown.

View File

@ -18,7 +18,7 @@ func InitRedis() error {
RedisClient = redis.NewClient(&redis.Options{ RedisClient = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", config.AppConfig.RedisHost, config.AppConfig.RedisPort), Addr: fmt.Sprintf("%s:%d", config.AppConfig.RedisHost, config.AppConfig.RedisPort),
Password: config.AppConfig.RedisPassword, Password: config.AppConfig.RedisPassword,
DB: 0, // 使用默认数据库 DB: config.AppConfig.RedisDB, // 使用默认数据库
}) })
// 测试连接 // 测试连接