-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(os/gcfg): Add file watcher with custom callback support #4446
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
Merged
Changes from 10 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5caa12f
feat(gcfg): 添加配置监听器功能
LanceAdd 67483fc
feat(gcfg):重构配置适配器以支持上下文传递
LanceAdd 80e31e5
Merge branch 'master' into fix/gcfg-watcher
hailaz e6ea72e
fix(os/gcfg): 更新操作上下文类型以支持gctx.StrKey
hailaz fc83375
fix(os/gcfg): 修复获取Operation Value类型
LanceAdd fc76c8c
fix(os/gcfg): 整 WithOperation 签名参数类型从 gctx.StrKey 到 string 以简化接口定义
LanceAdd d3b09ba
Apply gci import order changes
github-actions[bot] e60ed41
fix(contrib/config/nacos): 完善单元测试
LanceAdd c594e61
fix(contrib/config/nacos): 完善单元测试
LanceAdd 8b482fc
Merge branch 'master' into fix/gcfg-watcher
joy999 d4f5b87
fix(contrib/config/nacos): 优化配置变更通知逻辑,简化观察者调用
hailaz cf35fbf
fix(os/gcfg): 添加接口实现的编译时检查
hailaz 4294f9f
fix(contrib/config/nacos): 修复上下文获取方法,增加类型安全检查
hailaz 6734a9a
fix(contrib/config/polaris): - 在 polaris 客户端中实现配置监听器回调功能,补充缺少的注释
LanceAdd c4eb06c
Merge branch 'gogf:master' into fix/gcfg-watcher
LanceAdd 5972a83
Merge branch 'master' into fix/gcfg-watcher
hailaz 06fc475
Merge branch 'master' into fix/gcfg-watcher
hailaz 0e0d431
feat(contrib/config): 为 Apollo 和 Consul 配置中心添加监听器管理机制
LanceAdd d422c23
Apply gci import order changes
github-actions[bot] ac63193
feat(consul): 实现配置接口和监听接口
LanceAdd e7984b5
fix: 优化上下文设置方法,简化参数处理
hailaz 4e839d0
refactor: 统一适配器上下文创建方法,简化代码结构
hailaz a84162c
refactor: 重命名适配器上下文方法,统一内容设置和获取逻辑
hailaz ad32a9e
refactor: 统一适配器上下文操作常量,简化代码结构
hailaz b31b5d9
refactor: 优化配置变更函数中的断言逻辑,提升可读性
hailaz 6e546f6
feat(kubecm): 实现Kubecm配置监听和上下文适配器
LanceAdd 902c698
Apply gci import order changes
github-actions[bot] 851add6
feat(kubecm): 添加编译时接口实现检查
LanceAdd aaa9ad1
feat(kubecm): 添加注释
LanceAdd 6863030
Merge branch 'master' into fix/gcfg-watcher
hailaz b7716a9
Merge branch 'master' into fix/gcfg-watcher
hailaz 4f75591
Apply suggestion from @Copilot
hailaz f9659bf
Apply suggestion from @Copilot
hailaz c7c72c9
feat: 重构配置适配器,使用WatcherRegistry管理观察者
hailaz 5d4a6a6
Apply gci import order changes
github-actions[bot] 60d38de
refactor: 清理代码,移除多余的空行
hailaz 463b5bb
Merge branch 'master' into fix/gcfg-watcher
hailaz 258ab00
test(os/gcfg): 用 WaitGroup 替代 time.Sleep 同步 watcher 测试
hailaz 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
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
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,123 @@ | ||
| package nacos | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/gogf/gf/v2/os/gcfg" | ||
| "github.com/gogf/gf/v2/os/gctx" | ||
| ) | ||
|
|
||
| const ( | ||
| // KeyNamespace is the context key for namespace | ||
| KeyNamespace gctx.StrKey = "namespace" | ||
| // KeyGroup is the context key for group | ||
| KeyGroup gctx.StrKey = "group" | ||
| // KeyDataId is the context key for dataId | ||
| KeyDataId gctx.StrKey = "dataId" | ||
| ) | ||
|
|
||
| const ( | ||
| // OperationUpdate represents the update operation | ||
| OperationUpdate = "update" | ||
| ) | ||
|
|
||
| // NacosAdapterCtx is the context adapter for Nacos configuration | ||
| type NacosAdapterCtx struct { | ||
| Ctx context.Context | ||
| } | ||
|
|
||
| // NewNacosAdapterCtx creates and returns a new NacosAdapterCtx. | ||
| // If context is provided, it will be used; otherwise, a background context is created. | ||
| func NewNacosAdapterCtx(ctx ...context.Context) *NacosAdapterCtx { | ||
| if len(ctx) > 0 { | ||
| return &NacosAdapterCtx{ | ||
| Ctx: ctx[0], | ||
| } | ||
| } | ||
| return &NacosAdapterCtx{Ctx: context.Background()} | ||
| } | ||
|
|
||
| // GetNacosAdapterCtx creates a new NacosAdapterCtx with the given context | ||
| func GetNacosAdapterCtx(ctx context.Context) *NacosAdapterCtx { | ||
| return &NacosAdapterCtx{Ctx: ctx} | ||
| } | ||
|
|
||
| // WithOperation sets the operation in the context | ||
| func (n *NacosAdapterCtx) WithOperation(operation ...string) *NacosAdapterCtx { | ||
| if len(operation) > 0 { | ||
| n.Ctx = context.WithValue(n.Ctx, gcfg.OperationWrite, operation[0]) | ||
| } | ||
| return n | ||
| } | ||
|
|
||
| // WithNamespace sets the namespace in the context | ||
| func (n *NacosAdapterCtx) WithNamespace(namespace ...string) *NacosAdapterCtx { | ||
| if len(namespace) > 0 { | ||
| n.Ctx = context.WithValue(n.Ctx, KeyNamespace, namespace[0]) | ||
| } | ||
| return n | ||
| } | ||
|
|
||
| // WithGroup sets the group in the context | ||
| func (n *NacosAdapterCtx) WithGroup(group ...string) *NacosAdapterCtx { | ||
| if len(group) > 0 { | ||
| n.Ctx = context.WithValue(n.Ctx, KeyGroup, group[0]) | ||
| } | ||
| return n | ||
| } | ||
|
|
||
| // WithDataId sets the dataId in the context | ||
| func (n *NacosAdapterCtx) WithDataId(dataId ...string) *NacosAdapterCtx { | ||
| if len(dataId) > 0 { | ||
| n.Ctx = context.WithValue(n.Ctx, KeyDataId, dataId[0]) | ||
| } | ||
| return n | ||
| } | ||
|
|
||
| // WithSetContent sets the content in the context | ||
| func (n *NacosAdapterCtx) WithSetContent(content ...string) *NacosAdapterCtx { | ||
| if len(content) > 0 { | ||
| n.Ctx = context.WithValue(n.Ctx, gcfg.KeySetContent, content[0]) | ||
| } | ||
| return n | ||
| } | ||
|
|
||
| // GetNamespace retrieves the namespace from the context | ||
| func (n *NacosAdapterCtx) GetNamespace() string { | ||
| if v := n.Ctx.Value(KeyNamespace); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // GetGroup retrieves the group from the context | ||
| func (n *NacosAdapterCtx) GetGroup() string { | ||
| if v := n.Ctx.Value(KeyGroup); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // GetDataId retrieves the dataId from the context | ||
| func (n *NacosAdapterCtx) GetDataId() string { | ||
| if v := n.Ctx.Value(KeyDataId); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // GetSetContent retrieves the content from the context | ||
| func (n *NacosAdapterCtx) GetSetContent() string { | ||
| if v := n.Ctx.Value(gcfg.KeySetContent); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // GetOperation retrieves the operation from the context | ||
| func (n *NacosAdapterCtx) GetOperation() string { | ||
| if v := n.Ctx.Value(OperationUpdate); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } |
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
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,70 @@ | ||
| // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. | ||
| // | ||
| // This Source Code Form is subject to the terms of the MIT License. | ||
| // If a copy of the MIT was not distributed with this file, | ||
| // You can obtain one at https://github.com/gogf/gf. | ||
|
|
||
| // Package gcfg provides reading, caching and managing for configuration. | ||
| package gcfg | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| // AdapterContentCtx is the context for AdapterContent. | ||
| type AdapterContentCtx struct { | ||
| // Ctx is the context with configuration values | ||
| Ctx context.Context | ||
| } | ||
|
|
||
| // NewAdapterContentCtx creates and returns a new AdapterContentCtx. | ||
| // If ctx is provided, it uses that context, otherwise it creates a background context. | ||
| func NewAdapterContentCtx(ctx ...context.Context) *AdapterContentCtx { | ||
| if len(ctx) > 0 { | ||
| return &AdapterContentCtx{ | ||
| Ctx: ctx[0], | ||
| } | ||
| } | ||
| return &AdapterContentCtx{Ctx: context.Background()} | ||
| } | ||
|
|
||
| // GetAdapterContentCtx creates and returns an AdapterContentCtx with the given context. | ||
| func GetAdapterContentCtx(ctx context.Context) *AdapterContentCtx { | ||
| return &AdapterContentCtx{Ctx: ctx} | ||
| } | ||
|
|
||
| // WithOperation sets the operation in the context and returns the updated AdapterContentCtx. | ||
| // If operation is not provided, it does nothing. | ||
| func (a *AdapterContentCtx) WithOperation(operation ...string) *AdapterContentCtx { | ||
|
hailaz marked this conversation as resolved.
Outdated
|
||
| if len(operation) > 0 { | ||
| a.Ctx = context.WithValue(a.Ctx, KeyOperation, operation[0]) | ||
| } | ||
| return a | ||
| } | ||
|
|
||
| // WithSetContent sets the content in the context and returns the updated AdapterContentCtx. | ||
| // If content is not provided, it does nothing. | ||
| func (a *AdapterContentCtx) WithSetContent(content ...string) *AdapterContentCtx { | ||
| if len(content) > 0 { | ||
| a.Ctx = context.WithValue(a.Ctx, KeySetContent, content[0]) | ||
| } | ||
| return a | ||
| } | ||
|
|
||
| // GetOperation retrieves the operation from the context. | ||
| // Returns empty string if not found. | ||
| func (a *AdapterContentCtx) GetOperation() string { | ||
| if v := a.Ctx.Value(KeyOperation); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // GetSetContent retrieves the content from the context. | ||
| // Returns empty string if not found. | ||
| func (a *AdapterContentCtx) GetSetContent() string { | ||
| if v := a.Ctx.Value(KeySetContent); v != nil { | ||
| return v.(string) | ||
| } | ||
| return "" | ||
| } | ||
Oops, something went wrong.
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.