This commit is contained in:
2026-08-15 01:12:04 +08:00
parent f63acae353
commit 6698e59c3a
45 changed files with 725 additions and 415 deletions
+14 -5
View File
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc (unknown)
// protoc-gen-go v1.36.12
// protoc v7.35.1
// source: conf/conf.proto
package conf
@@ -1167,6 +1167,7 @@ func (x *AdminBackend_Email) GetIsLoginAuth() bool {
type AdminBackend_Media struct {
state protoimpl.MessageState `protogen:"open.v1"`
SessionTtl int32 `protobuf:"varint,1,opt,name=session_ttl,json=sessionTtl,proto3" json:"session_ttl,omitempty"`
MaxFileSize int64 `protobuf:"varint,2,opt,name=max_file_size,json=maxFileSize,proto3" json:"max_file_size,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -1208,6 +1209,13 @@ func (x *AdminBackend_Media) GetSessionTtl() int32 {
return 0
}
func (x *AdminBackend_Media) GetMaxFileSize() int64 {
if x != nil {
return x.MaxFileSize
}
return 0
}
type AdminBackend_Disk struct {
state protoimpl.MessageState `protogen:"open.v1"`
MountPoint string `protobuf:"bytes,1,opt,name=mount_point,json=mountPoint,proto3" json:"mount_point,omitempty"`
@@ -2046,7 +2054,7 @@ const file_conf_conf_proto_rawDesc = "" +
"\x12connect_timeout_ms\x18\n" +
" \x01(\x03R\x10connectTimeoutMs\x12\x15\n" +
"\x06is_zap\x18\v \x01(\bR\x05isZap\x120\n" +
"\x05hosts\x18\f \x03(\v2\x1a.kratos.api.Data.MongoHostR\x05hosts\"\x90\x1b\n" +
"\x05hosts\x18\f \x03(\v2\x1a.kratos.api.Data.MongoHostR\x05hosts\"\xb4\x1b\n" +
"\fAdminBackend\x12#\n" +
"\rrouter_prefix\x18\x01 \x01(\tR\frouterPrefix\x12.\n" +
"\x03jwt\x18\x02 \x01(\v2\x1c.kratos.api.AdminBackend.JWTR\x03jwt\x12:\n" +
@@ -2089,10 +2097,11 @@ const file_conf_conf_proto_rawDesc = "" +
"\bnickname\x18\x05 \x01(\tR\bnickname\x12\x12\n" +
"\x04port\x18\x06 \x01(\x05R\x04port\x12\x15\n" +
"\x06is_ssl\x18\a \x01(\bR\x05isSsl\x12\"\n" +
"\ris_login_auth\x18\b \x01(\bR\visLoginAuth\x1a(\n" +
"\ris_login_auth\x18\b \x01(\bR\visLoginAuth\x1aL\n" +
"\x05Media\x12\x1f\n" +
"\vsession_ttl\x18\x01 \x01(\x05R\n" +
"sessionTtl\x1a'\n" +
"sessionTtl\x12\"\n" +
"\rmax_file_size\x18\x02 \x01(\x03R\vmaxFileSize\x1a'\n" +
"\x04Disk\x12\x1f\n" +
"\vmount_point\x18\x01 \x01(\tR\n" +
"mountPoint\x1a\xc3\x01\n" +
+1
View File
@@ -126,6 +126,7 @@ message AdminBackend {
message Media {
int32 session_ttl = 1;
int64 max_file_size = 2;
}
message Disk {
+37 -3
View File
@@ -1,6 +1,7 @@
package conf
import (
"sync"
"sync/atomic"
"google.golang.org/protobuf/proto"
@@ -9,7 +10,10 @@ import (
// Runtime owns the active immutable configuration snapshot. Callers always
// receive clones so a config file reload cannot race with request handling.
type Runtime struct {
snapshot atomic.Pointer[runtimeSnapshot]
snapshot atomic.Pointer[runtimeSnapshot]
mu sync.RWMutex
nextID uint64
listeners map[uint64]func(*Data, *AdminBackend)
}
type runtimeSnapshot struct {
@@ -18,7 +22,7 @@ type runtimeSnapshot struct {
}
func NewRuntime(data *Data, admin *AdminBackend) *Runtime {
runtime := &Runtime{}
runtime := &Runtime{listeners: make(map[uint64]func(*Data, *AdminBackend))}
runtime.Replace(data, admin)
return runtime
}
@@ -38,7 +42,37 @@ func cloneAdmin(value *AdminBackend) *AdminBackend {
}
func (r *Runtime) Replace(data *Data, admin *AdminBackend) {
r.snapshot.Store(&runtimeSnapshot{data: cloneData(data), admin: cloneAdmin(admin)})
data = cloneData(data)
admin = cloneAdmin(admin)
r.snapshot.Store(&runtimeSnapshot{data: data, admin: admin})
r.mu.RLock()
listeners := make([]func(*Data, *AdminBackend), 0, len(r.listeners))
for _, listener := range r.listeners {
listeners = append(listeners, listener)
}
r.mu.RUnlock()
for _, listener := range listeners {
listener(cloneData(data), cloneAdmin(admin))
}
}
// Subscribe registers a callback invoked after every successful runtime
// configuration replacement. It is used by long-lived clients such as the
// logger and other long-lived clients that must follow runtime config changes.
func (r *Runtime) Subscribe(listener func(*Data, *AdminBackend)) func() {
if listener == nil {
return func() {}
}
r.mu.Lock()
r.nextID++
id := r.nextID
r.listeners[id] = listener
r.mu.Unlock()
return func() {
r.mu.Lock()
delete(r.listeners, id)
r.mu.Unlock()
}
}
func (r *Runtime) Data() *Data {