From 0cab1c6c616167dbbdf73ecf874b3726dfd38f2d Mon Sep 17 00:00:00 2001 From: Yavolte Date: Thu, 19 Jun 2025 11:06:48 +0800 Subject: [PATCH] update proto file --- config/config.go | 61 ----------------------------------------- go.mod | 2 +- go.sum | 2 -- pb/organize.pb.go | 12 ++++---- pb/organize.proto | 4 +-- pb/organize_http.pb.go | 2 +- pb/organize_model.pb.go | 6 ++-- pb/system.pb.go | 10 +++---- pb/system.proto | 4 +-- pb/system_http.pb.go | 2 +- pb/system_model.pb.go | 6 ++-- pkg/cfgload/file.go | 30 ++++++++++++++++++++ 12 files changed, 54 insertions(+), 87 deletions(-) delete mode 100644 config/config.go create mode 100644 pkg/cfgload/file.go diff --git a/config/config.go b/config/config.go deleted file mode 100644 index 0f1de9a..0000000 --- a/config/config.go +++ /dev/null @@ -1,61 +0,0 @@ -package config - -import ( - "os" - "strconv" -) - -type Database struct { - Driver string `json:"driver" yaml:"driver"` - DSN string `json:"dsn" yaml:"dsn"` -} - -type Redis struct { - Addr string `json:"addr" yaml:"addr"` - Password string `json:"password" yaml:"password"` - DB int `json:"db" yaml:"db"` -} - -type Auth struct { - TTL int64 `json:"ttl" yaml:"ttl"` - Secret string `json:"secret" yaml:"secret"` - AllowUrls []string `json:"allow_urls" yaml:"allowUrls"` -} - -type Translate struct { - ClientKey string `json:"client_key" yaml:"clientKey"` - ServerKey string `json:"server_key" yaml:"serverKey"` - ValidateUrl string `json:"validate_url" yaml:"validateUrl"` -} - -type Config struct { - Auth Auth `json:"auth" yaml:"auth"` - Redis Redis `json:"redis" yaml:"redis"` - Translate Translate `json:"translate" yaml:"translate"` - Database Database `json:"database" yaml:"database"` -} - -func (c *Config) getEnvVariable(key string, val string) string { - s := os.Getenv(key) - if s == "" { - return val - } - return s -} - -func (c *Config) FromEnvironment() { - c.Auth.Secret = c.getEnvVariable("AUTH_SECRET", "secret") - c.Auth.TTL = 7200 - - c.Database.Driver = c.getEnvVariable("DATABASE_DRIVER", "mysql") - c.Database.DSN = os.Getenv("DATABASE_DSN") - if c.Database.Driver == "" { - c.Database.Driver = "mysql" - } - - c.Redis.Addr = os.Getenv("REDIS_ADDRESS") - c.Redis.Password = os.Getenv("REDIS_PASSWORD") - if n, err := strconv.Atoi(os.Getenv("REDIS_DB")); err == nil { - c.Redis.DB = n - } -} diff --git a/go.mod b/go.mod index 644508b..a3ffd95 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( golang.org/x/sync v0.12.0 google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb google.golang.org/grpc v1.72.2 + gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/postgres v1.6.0 gorm.io/driver/sqlite v1.6.0 ) @@ -65,5 +66,4 @@ require ( golang.org/x/net v0.38.0 // indirect golang.org/x/sys v0.31.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5cbeb3f..1b38615 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -git.nobla.cn/golang/aeus v0.0.8 h1:mifdMOredbOfUNnP193+IjR1gR68O+2R3DVEhi3N4GE= -git.nobla.cn/golang/aeus v0.0.8/go.mod h1:oOEwqIp6AhKKqj6sLFO8x7IycOROYHCb/2/CjF4+9CU= git.nobla.cn/golang/kos v0.1.32 h1:sFVCA7vKc8dPUd0cxzwExOSPX2mmMh2IuwL6cYS1pBc= git.nobla.cn/golang/kos v0.1.32/go.mod h1:35Z070+5oB39WcVrh5DDlnVeftL/Ccmscw2MZFe9fUg= git.nobla.cn/golang/rest v0.1.2 h1:vF5perbveRcCF5Pb60yxHjvGpx/zX+D1qzdceqIwg+E= diff --git a/pb/organize.pb.go b/pb/organize.pb.go index 123eb84..21ef0a1 100644 --- a/pb/organize.pb.go +++ b/pb/organize.pb.go @@ -2748,7 +2748,7 @@ const file_organize_proto_rawDesc = "" + "\vdescription\x18\f \x01(\tBO\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19C\n" + "\tsize:1024\x12\f备注说明\x1a\x1ecreate;update;view;export;list*\btextareaR\vdescription\x127\n" + "\bposition\x18\r \x01(\x03B\x1b\xb2\xb9\x19\x17\x12\x06排序\x1a\rcreate;updateR\bposition:\v\xba\xb9\x19\a\n" + - "\x05menus\"\xbd\x03\n" + + "\x05menus\"\xd1\x03\n" + "\x04Role\x12*\n" + "\x02id\x18\x01 \x01(\x03B\x1a\xb2\xb9\x19\x16\n" + "\n" + @@ -2757,11 +2757,11 @@ const file_organize_proto_rawDesc = "" + "created_at\x18\x02 \x01(\x03B\x1f\xb2\xb9\x19\x1b\x12\f创建时间\x1a\vview;exportR\tcreatedAt\x12E\n" + "\n" + "updated_at\x18\x03 \x01(\x03B&\xb2\xb9\x19\"\n" + - "\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12M\n" + - "\x04name\x18\x04 \x01(\tB9\xfaB\x04r\x02\x18<\xb2\xb9\x19.\n" + - "\rindex;size:60\x12\f角色名称2\x0freadonly:updateR\x04name\x128\n" + - "\x05label\x18\x05 \x01(\tB\"\xfaB\x04r\x02\x18<\xb2\xb9\x19\x17\n" + - "\asize:60\x12\f角色标题R\x05label\x12l\n" + + "\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12W\n" + + "\x04name\x18\x04 \x01(\tBC\xfaB\x04r\x02\x18<\xb2\xb9\x198\n" + + "\rindex;size:60\x12\f角色名称2\x0freadonly:update:\brequiredR\x04name\x12B\n" + + "\x05label\x18\x05 \x01(\tB,\xfaB\x04r\x02\x18<\xb2\xb9\x19!\n" + + "\asize:60\x12\f角色标题:\brequiredR\x05label\x12l\n" + "\vdescription\x18\x06 \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" + "\tsize:1024\x12\f备注说明\x1a\x19list;create;update;export*\btextareaR\vdescription:\v\xba\xb9\x19\a\n" + "\x05roles\"\xb1\x03\n" + diff --git a/pb/organize.proto b/pb/organize.proto index 05de8e1..7cde9b4 100644 --- a/pb/organize.proto +++ b/pb/organize.proto @@ -37,8 +37,8 @@ message Role { int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment: "角色ID"}]; int64 created_at = 2 [(aeus.field)={scenarios:"view;export",comment:"创建时间"}]; int64 updated_at = 3 [(aeus.field)={gorm:"index",scenarios:"view;export",comment:"更新时间"}]; - string name = 4 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",comment: "角色名称"},(validate.rules).string = {max_len: 60}]; - string label = 5 [(aeus.field)={gorm:"size:60",comment: "角色标题"},(validate.rules).string = {max_len: 60}]; + string name = 4 [(aeus.field)={gorm:"index;size:60",rule:"required",props:"readonly:update",comment: "角色名称"},(validate.rules).string = {max_len: 60}]; + string label = 5 [(aeus.field)={gorm:"size:60",rule:"required",comment: "角色标题"},(validate.rules).string = {max_len: 60}]; string description = 6 [(aeus.field)={gorm:"size:1024",scenarios:"list;create;update;export",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}]; } diff --git a/pb/organize_http.pb.go b/pb/organize_http.pb.go index d198fd6..4130cc2 100644 --- a/pb/organize_http.pb.go +++ b/pb/organize_http.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: organize.proto -// date: 2025-06-18 15:37:30 +// date: 2025-06-19 11:06:34 package pb diff --git a/pb/organize_model.pb.go b/pb/organize_model.pb.go index 4a3be75..f316d2a 100644 --- a/pb/organize_model.pb.go +++ b/pb/organize_model.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: organize.proto -// date: 2025-06-18 15:37:30 +// date: 2025-06-19 11:06:34 package pb @@ -98,8 +98,8 @@ type RoleModel struct { Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"角色ID"` CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"view;export"` UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"index;column:updated_at" comment:"更新时间" scenarios:"view;export"` - Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"角色名称" props:"readonly:update"` - Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60;column:label" comment:"角色标题"` + Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"角色名称" props:"readonly:update" rule:"required"` + Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60;column:label" comment:"角色标题" rule:"required"` Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"list;create;update;export" format:"textarea"` } diff --git a/pb/system.pb.go b/pb/system.pb.go index fd75cac..92c4f76 100644 --- a/pb/system.pb.go +++ b/pb/system.pb.go @@ -355,7 +355,7 @@ const file_system_proto_rawDesc = "" + "\vdescription\x18\x06 \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" + "\tsize:1024\x12\f备注说明\x1a\x19create;update;view;export*\btextareaR\vdescription:\x0e\xba\xb9\x19\n" + "\n" + - "\bsettings\"\xd8\x05\n" + + "\bsettings\"\xe2\x05\n" + "\bActivity\x12$\n" + "\x02id\x18\x01 \x01(\x03B\x14\xb2\xb9\x19\x10\n" + "\n" + @@ -363,13 +363,13 @@ const file_system_proto_rawDesc = "" + "\n" + "created_at\x18\x02 \x01(\x03B-\xb2\xb9\x19)\x12\f创建时间\x1a\x19search;search;view;exportR\tcreatedAt\x12W\n" + "\x03uid\x18\x03 \x01(\tBE\xfaB\x06r\x04\x10\x05\x18\x14\xb2\xb9\x198\n" + - "\rindex;size:20\x12\x06用户*\x04user2\x0freadonly:update:\brequiredR\x03uid\x12\xbf\x01\n" + - "\x06action\x18\x04 \x01(\tB\xa6\x01\xb2\xb9\x19\xa1\x01\n" + - "!index;size:20;not null;default:''\x12\x06行为\x1a%search;list;create;update;view;export2\rmatch:exactlyR>create:新建#198754;update:更新#f09d00;delete:删除#e63757R\x06action\x12h\n" + + "\rindex;size:20\x12\x06用户*\x04user2\x0freadonly:update:\brequiredR\x03uid\x12\xc9\x01\n" + + "\x06action\x18\x04 \x01(\tB\xb0\x01\xb2\xb9\x19\xab\x01\n" + + "!index;size:20;not null;default:''\x12\x06行为\x1a%search;list;create;update;view;export2\rmatch:exactly:\brequiredR>create:新建#198754;update:更新#f09d00;delete:删除#e63757R\x06action\x12h\n" + "\x06module\x18\x05 \x01(\tBP\xb2\xb9\x19L\n" + "\x1bsize:60;not null;default:''\x12\x06模块\x1a%search;list;create;update;view;exportR\x06module\x12_\n" + "\x05table\x18\x06 \x01(\tBI\xb2\xb9\x19E\n" + - "\x1bsize:60;not null;default:''\x12\x06数据\x1a\x1elist;create;update;view;exportR\x05table\x12`\n" + + "\x1bsize:60;not null;default:''\x12\x06模型\x1a\x1elist;create;update;view;exportR\x05table\x12`\n" + "\x04data\x18\a \x01(\tBL\xb2\xb9\x19H\n" + "\x1esize:10240;not null;default:''\x12\x06内容\x1a\x1elist;create;update;view;exportR\x04data:\x10\xba\xb9\x19\f\n" + "\n" + diff --git a/pb/system.proto b/pb/system.proto index 1036db0..77b27d8 100644 --- a/pb/system.proto +++ b/pb/system.proto @@ -32,9 +32,9 @@ message Activity { int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"ID"}]; int64 created_at = 2 [(aeus.field)={scenarios:"search;search;view;export",comment:"创建时间"}]; string uid = 3 [(aeus.field)={gorm:"index;size:20",rule:"required",props:"readonly:update",format:"user",comment: "用户"},(validate.rules).string = {min_len: 5, max_len: 20}]; - string action = 4 [(aeus.field)={props:"match:exactly",gorm:"index;size:20;not null;default:''",comment:"行为",enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757",scenarios:"search;list;create;update;view;export"}]; + string action = 4 [(aeus.field)={props:"match:exactly",rule:"required",gorm:"index;size:20;not null;default:''",comment:"行为",enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757",scenarios:"search;list;create;update;view;export"}]; string module = 5 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"模块",scenarios:"search;list;create;update;view;export"}]; - string table = 6 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"数据",scenarios:"list;create;update;view;export"}]; + string table = 6 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"模型",scenarios:"list;create;update;view;export"}]; string data = 7 [(aeus.field)={gorm:"size:10240;not null;default:''",comment:"内容",scenarios:"list;create;update;view;export"}]; } diff --git a/pb/system_http.pb.go b/pb/system_http.pb.go index f21648a..3a75ef5 100644 --- a/pb/system_http.pb.go +++ b/pb/system_http.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: system.proto -// date: 2025-06-18 15:37:30 +// date: 2025-06-19 11:06:34 package pb diff --git a/pb/system_model.pb.go b/pb/system_model.pb.go index f7daf4a..40d0004 100644 --- a/pb/system_model.pb.go +++ b/pb/system_model.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: system.proto -// date: 2025-06-18 15:37:30 +// date: 2025-06-19 11:06:34 package pb @@ -77,9 +77,9 @@ type ActivityModel struct { Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"ID"` CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"search;search;view;export"` Uid string `json:"uid" yaml:"uid" xml:"uid" gorm:"index;size:20;column:uid" comment:"用户" format:"user" props:"readonly:update" rule:"required"` - Action string `json:"action" yaml:"action" xml:"action" gorm:"index;size:20;not null;default:'';column:action" comment:"行为" scenarios:"search;list;create;update;view;export" props:"match:exactly" enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757"` + Action string `json:"action" yaml:"action" xml:"action" gorm:"index;size:20;not null;default:'';column:action" comment:"行为" scenarios:"search;list;create;update;view;export" props:"match:exactly" rule:"required" enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757"` Module string `json:"module" yaml:"module" xml:"module" gorm:"size:60;not null;default:'';column:module" comment:"模块" scenarios:"search;list;create;update;view;export"` - Table string `json:"table" yaml:"table" xml:"table" gorm:"size:60;not null;default:'';column:table" comment:"数据" scenarios:"list;create;update;view;export"` + Table string `json:"table" yaml:"table" xml:"table" gorm:"size:60;not null;default:'';column:table" comment:"模型" scenarios:"list;create;update;view;export"` Data string `json:"data" yaml:"data" xml:"data" gorm:"size:10240;not null;default:'';column:data" comment:"内容" scenarios:"list;create;update;view;export"` } diff --git a/pkg/cfgload/file.go b/pkg/cfgload/file.go new file mode 100644 index 0000000..790bdb6 --- /dev/null +++ b/pkg/cfgload/file.go @@ -0,0 +1,30 @@ +package cfgload + +import ( + "encoding/json" + "encoding/xml" + "os" + "path" + + "gopkg.in/yaml.v3" +) + +// FromFile loads configuration from file +func FromFile(filepath string, cfg any) (err error) { + var ( + buf []byte + ) + if buf, err = os.ReadFile(filepath); err != nil { + return + } + ext := path.Ext(filepath) + switch ext { + case ".json": + err = json.Unmarshal(buf, cfg) + case ".xml": + err = xml.Unmarshal(buf, cfg) + case ".yaml", ".yml": + err = yaml.Unmarshal(buf, cfg) + } + return +}