任务三
This commit is contained in:
+1791
-1104
File diff suppressed because it is too large
Load Diff
+182
-104
@@ -7,11 +7,25 @@ import "google/protobuf/duration.proto";
|
||||
|
||||
message Bootstrap {
|
||||
Server server = 1;
|
||||
Data data = 2;
|
||||
JWT jwt = 3;
|
||||
Casbin casbin = 4;
|
||||
Captcha captcha = 5;
|
||||
Upload upload = 6;
|
||||
JWT jwt = 2;
|
||||
System system = 3;
|
||||
Captcha captcha = 4;
|
||||
Mysql mysql = 5;
|
||||
Pgsql pgsql = 6;
|
||||
Sqlite sqlite = 7;
|
||||
Redis redis = 8;
|
||||
Local local = 9;
|
||||
Qiniu qiniu = 10;
|
||||
Minio minio = 11;
|
||||
AliyunOss aliyun_oss = 12;
|
||||
TencentCos tencent_cos = 13;
|
||||
AwsS3 aws_s3 = 14;
|
||||
CloudflareR2 cloudflare_r2 = 15;
|
||||
HuaweiObs huawei_obs = 16;
|
||||
Email email = 17;
|
||||
Excel excel = 18;
|
||||
Cors cors = 19;
|
||||
Zap zap = 20;
|
||||
}
|
||||
|
||||
message Server {
|
||||
@@ -29,27 +43,6 @@ message Server {
|
||||
GRPC grpc = 2;
|
||||
}
|
||||
|
||||
message Data {
|
||||
message Database {
|
||||
string driver = 1;
|
||||
string source = 2;
|
||||
string table_prefix = 3;
|
||||
int32 max_idle_conns = 4;
|
||||
int32 max_open_conns = 5;
|
||||
int32 max_lifetime = 6;
|
||||
bool log_mode = 7;
|
||||
}
|
||||
message Redis {
|
||||
string addr = 1;
|
||||
string password = 2;
|
||||
int32 db = 3;
|
||||
bool use_cluster = 4;
|
||||
repeated string cluster_addrs = 5;
|
||||
}
|
||||
Database database = 1;
|
||||
Redis redis = 2;
|
||||
}
|
||||
|
||||
message JWT {
|
||||
string signing_key = 1;
|
||||
string expires_time = 2;
|
||||
@@ -57,8 +50,16 @@ message JWT {
|
||||
string issuer = 4;
|
||||
}
|
||||
|
||||
message Casbin {
|
||||
string model_path = 1;
|
||||
message System {
|
||||
string env = 1;
|
||||
string db_type = 2;
|
||||
string oss_type = 3;
|
||||
bool use_redis = 4;
|
||||
bool use_multipoint = 5;
|
||||
int32 iplimit_count = 6;
|
||||
int32 iplimit_time = 7;
|
||||
string router_prefix = 8;
|
||||
bool use_strict_auth = 9;
|
||||
}
|
||||
|
||||
message Captcha {
|
||||
@@ -69,80 +70,157 @@ message Captcha {
|
||||
int32 open_captcha_timeout = 5;
|
||||
}
|
||||
|
||||
message Upload {
|
||||
string type = 1;
|
||||
string path = 2;
|
||||
int64 max_size = 3;
|
||||
|
||||
message Local {
|
||||
string store_path = 1;
|
||||
}
|
||||
message Aliyun {
|
||||
string endpoint = 1;
|
||||
string access_key_id = 2;
|
||||
string access_key_secret = 3;
|
||||
string bucket_name = 4;
|
||||
string bucket_url = 5;
|
||||
string base_path = 6;
|
||||
}
|
||||
message Tencent {
|
||||
string bucket = 1;
|
||||
string region = 2;
|
||||
string secret_id = 3;
|
||||
string secret_key = 4;
|
||||
string base_url = 5;
|
||||
string path_prefix = 6;
|
||||
}
|
||||
message Qiniu {
|
||||
string zone = 1;
|
||||
string bucket = 2;
|
||||
string img_path = 3;
|
||||
string access_key = 4;
|
||||
string secret_key = 5;
|
||||
bool use_https = 6;
|
||||
bool use_cdn_domains = 7;
|
||||
}
|
||||
message Minio {
|
||||
string id = 1;
|
||||
string secret = 2;
|
||||
string bucket = 3;
|
||||
string endpoint = 4;
|
||||
string base_path = 5;
|
||||
bool use_ssl = 6;
|
||||
}
|
||||
message AwsS3 {
|
||||
string bucket = 1;
|
||||
string region = 2;
|
||||
string endpoint = 3;
|
||||
string secret_id = 4;
|
||||
string secret_key = 5;
|
||||
string base_url = 6;
|
||||
string path_prefix = 7;
|
||||
bool s3_force_path_style = 8;
|
||||
bool disable_ssl = 9;
|
||||
}
|
||||
message HuaweiObs {
|
||||
string path = 1;
|
||||
string bucket = 2;
|
||||
string endpoint = 3;
|
||||
string access_key = 4;
|
||||
string secret_key = 5;
|
||||
}
|
||||
message CloudflareR2 {
|
||||
string bucket = 1;
|
||||
string base_url = 2;
|
||||
string path = 3;
|
||||
string account_id = 4;
|
||||
string access_key_id = 5;
|
||||
string secret_access_key = 6;
|
||||
}
|
||||
|
||||
Local local = 4;
|
||||
Aliyun aliyun = 5;
|
||||
Tencent tencent = 6;
|
||||
Qiniu qiniu = 7;
|
||||
Minio minio = 8;
|
||||
AwsS3 aws_s3 = 9;
|
||||
HuaweiObs huawei_obs = 10;
|
||||
CloudflareR2 cloudflare_r2 = 11;
|
||||
|
||||
message Mysql {
|
||||
string path = 1;
|
||||
string port = 2;
|
||||
string config = 3;
|
||||
string db_name = 4;
|
||||
string username = 5;
|
||||
string password = 6;
|
||||
int32 max_idle_conns = 7;
|
||||
int32 max_open_conns = 8;
|
||||
string log_mode = 9;
|
||||
bool log_zap = 10;
|
||||
}
|
||||
|
||||
message Pgsql {
|
||||
string path = 1;
|
||||
string port = 2;
|
||||
string config = 3;
|
||||
string db_name = 4;
|
||||
string username = 5;
|
||||
string password = 6;
|
||||
int32 max_idle_conns = 7;
|
||||
int32 max_open_conns = 8;
|
||||
string log_mode = 9;
|
||||
bool log_zap = 10;
|
||||
}
|
||||
|
||||
message Sqlite {
|
||||
string path = 1;
|
||||
string db_name = 2;
|
||||
int32 max_idle_conns = 3;
|
||||
int32 max_open_conns = 4;
|
||||
string log_mode = 5;
|
||||
bool log_zap = 6;
|
||||
}
|
||||
|
||||
message Redis {
|
||||
bool use_cluster = 1;
|
||||
string addr = 2;
|
||||
string password = 3;
|
||||
int32 db = 4;
|
||||
repeated string cluster_addrs = 5;
|
||||
}
|
||||
|
||||
message Local {
|
||||
string path = 1;
|
||||
string store_path = 2;
|
||||
}
|
||||
|
||||
message Qiniu {
|
||||
string zone = 1;
|
||||
string bucket = 2;
|
||||
string img_path = 3;
|
||||
bool use_https = 4;
|
||||
string access_key = 5;
|
||||
string secret_key = 6;
|
||||
bool use_cdn_domains = 7;
|
||||
}
|
||||
|
||||
message Minio {
|
||||
string endpoint = 1;
|
||||
string access_key_id = 2;
|
||||
string access_key_secret = 3;
|
||||
string bucket_name = 4;
|
||||
bool use_ssl = 5;
|
||||
string base_path = 6;
|
||||
string bucket_url = 7;
|
||||
}
|
||||
|
||||
message AliyunOss {
|
||||
string endpoint = 1;
|
||||
string access_key_id = 2;
|
||||
string access_key_secret = 3;
|
||||
string bucket_name = 4;
|
||||
string bucket_url = 5;
|
||||
string base_path = 6;
|
||||
}
|
||||
|
||||
message TencentCos {
|
||||
string bucket = 1;
|
||||
string region = 2;
|
||||
string secret_id = 3;
|
||||
string secret_key = 4;
|
||||
string base_url = 5;
|
||||
string path_prefix = 6;
|
||||
}
|
||||
|
||||
message AwsS3 {
|
||||
string bucket = 1;
|
||||
string region = 2;
|
||||
string endpoint = 3;
|
||||
bool s3_force_path_style = 4;
|
||||
bool disable_ssl = 5;
|
||||
string secret_id = 6;
|
||||
string secret_key = 7;
|
||||
string base_url = 8;
|
||||
string path_prefix = 9;
|
||||
}
|
||||
|
||||
message CloudflareR2 {
|
||||
string bucket = 1;
|
||||
string base_url = 2;
|
||||
string path = 3;
|
||||
string account_id = 4;
|
||||
string access_key_id = 5;
|
||||
string secret_access_key = 6;
|
||||
}
|
||||
|
||||
message HuaweiObs {
|
||||
string path = 1;
|
||||
string bucket = 2;
|
||||
string endpoint = 3;
|
||||
string access_key = 4;
|
||||
string secret_key = 5;
|
||||
}
|
||||
|
||||
message Email {
|
||||
string to = 1;
|
||||
int32 port = 2;
|
||||
string from = 3;
|
||||
string host = 4;
|
||||
bool is_ssl = 5;
|
||||
string secret = 6;
|
||||
string nickname = 7;
|
||||
}
|
||||
|
||||
message Excel {
|
||||
string dir = 1;
|
||||
}
|
||||
|
||||
message Cors {
|
||||
string mode = 1;
|
||||
repeated CorsWhitelist whitelist = 2;
|
||||
}
|
||||
|
||||
message CorsWhitelist {
|
||||
string allow_origin = 1;
|
||||
string allow_headers = 2;
|
||||
string allow_methods = 3;
|
||||
string expose_headers = 4;
|
||||
bool allow_credentials = 5;
|
||||
}
|
||||
|
||||
message Zap {
|
||||
string level = 1;
|
||||
string format = 2;
|
||||
string prefix = 3;
|
||||
string director = 4;
|
||||
bool show_line = 5;
|
||||
string encode_level = 6;
|
||||
string stacktrace_key = 7;
|
||||
bool log_in_console = 8;
|
||||
int32 retention_day = 9;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kra/internal/conf"
|
||||
"kra/internal/data/query"
|
||||
|
||||
@@ -20,8 +21,10 @@ type Data struct {
|
||||
}
|
||||
|
||||
// NewDB 创建数据库连接
|
||||
func NewDB(c *conf.Data) (*gorm.DB, error) {
|
||||
db, err := gorm.Open(mysql.Open(c.Database.Source), &gorm.Config{
|
||||
func NewDB(c *conf.Mysql) (*gorm.DB, error) {
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?%s",
|
||||
c.Username, c.Password, c.Path, c.Port, c.DbName, c.Config)
|
||||
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user