Comments (22)
It seems like you've got this under control, if you want help or have specific questions, let me know what I can do for you!
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from kratos.
基于proto生成结构体 并发安全的配置热更新,支持配置validate option选项
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Generate structure based on proto, concurrent and safe configuration hot update, support configuration of validate option option
from kratos.
基于proto生成结构体 并发安全的配置热更新,支持配置validate option选项
@xiongpan828
These features are already supported.
- In
kratos-layout
, proto is used as the configuration definition by default - It is inherently concurrency secure
- Use
PGV
directly to validate.
from kratos.
基于proto生成结构体配置安全的配置热更新,支持配置validate选项选项
@xiongpan828 这些功能已经得到支持。
- 中
kratos-layout
,默认使用proto作为配置定义- 它本质上是并发安全的
- 直接使用
PGV
来验证。
- 目前
Watch
需要选择一个key,如果想监听配置任意位置更新呢 - 当前配置结构体一直读取过程中,热更新进行了set ,底层配置上并发安全的,但是结构体不是
PGV
生成校验代码目前是在外部显示调用,如果放框架内部是不是要优雅一点
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Secure configuration hot update based on proto generated structure configuration, supports configuration of validate option options
@xiongpan828 These features are already supported.
- In
kratos-layout
, proto is used as the configuration definition by default- It is inherently concurrency safe
- Use
PGV
directly to verify.
- Currently,
Watch
needs to select a key. What if you want to monitor the configuration for updates at any location? - While the current configuration structure is being read, the hot update is set. The underlying configuration is concurrency-safe, but the structure is not.
- The verification code generated by
PGV
is currently called externally. If placed inside the framework, should it be more elegant?
from kratos.
基于proto生成结构体配置安全的配置热更新,支持配置validate选项选项
@xiongpan828 这些功能已经得到支持。
- 中
kratos-layout
,默认使用proto作为配置定义- 它本质上是并发安全的
- 直接使用
PGV
来验证。
- 目前
Watch
需要选择一个key,如果想监听配置任意位置更新呢- 当前配置结构体一直读取过程中,热更新进行了set ,底层配置上并发安全的,但是结构体不是
PGV
生成校验代码目前是在外部显示调用,如果放框架内部是不是要优雅一点
@xiongpan828
- Watch any key, all you need to do is set a root key。Can consider supporting the entire watch configuration, but I haven't figured out if it's necessary yet.
The config package focuses more on how to parse, merge, and finally serialize configurations into user structures
- The security of the structure should not be guaranteed by the framework, as this part itself is user-defined. Config only ensures that the dynamic update process is concurrent and secure within the config package, and provides a hook externally. This part should be implemented by users by locking the structure.
- The config package should not rely on the PGV library, as it is not a mandatory component to rely on.
from kratos.
注入到 context.Context
。
我现在的做法(参考):
package main
import (
"context"
"fmt"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos-ecosystem/components/v2/config"
"github.com/go-kratos-ecosystem/components/v2/env"
"github.com/go-kratos-ecosystem/components/v2/provider"
"github.com/go-kratos-ecosystem/components/v2/timezone"
)
type Config struct {
Host string
}
func main() {
ctx, err := provider.Pipe(context.Background(),
// 注入到 context 中
config.Provider(&Config{
Host: "localhost",
}),
// 注入其他的 Provider
timezone.Provider(timezone.Local("Asia/Shanghai")),
env.Provider(env.Prod),
)
if err != nil {
panic(err)
}
app := kratos.New(
kratos.Context(ctx),
kratos.Server(),
)
if err := app.Run(); err != nil {
panic(err)
}
}
// DemoService is a demo service.
func DemoService(ctx context.Context) error {
cfg, ok := config.FromContext[*Config](ctx)
if !ok {
return fmt.Errorf("config not found")
}
_ = cfg
return nil
}
参考资料:
- 相关包的地址:https://github.com/go-kratos-ecosystem/components/tree/7af8d79f62c29cb59c3261e456180da7265ecbca
from kratos.
注入到
context.Context
。我现在的做法(参考):
package main import ( "context" "fmt" "github.com/go-kratos/kratos/v2" "github.com/go-kratos-ecosystem/components/v2/config" "github.com/go-kratos-ecosystem/components/v2/env" "github.com/go-kratos-ecosystem/components/v2/provider" "github.com/go-kratos-ecosystem/components/v2/timezone" ) type Config struct { Host string } func main() { ctx, err := provider.Pipe(context.Background(), // 注入到 context 中 config.Provider(&Config{ Host: "localhost", }), // 注入其他的 Provider timezone.Provider(timezone.Local("Asia/Shanghai")), env.Provider(env.Prod), ) if err != nil { panic(err) } app := kratos.New( kratos.Context(ctx), kratos.Server(), ) if err := app.Run(); err != nil { panic(err) } } // DemoService is a demo service. func DemoService(ctx context.Context) error { cfg, ok := config.FromContext[*Config](ctx) if !ok { return fmt.Errorf("config not found") } _ = cfg return nil }参考资料:
👍👍👍谢谢 get了
from kratos.
菜鸟咨询:能否进行配置文件没配置的部分给默认值 (比较推荐的方式) 😁
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Rookie consultation: Is it possible to give default values to the unconfigured parts of the configuration file (a more recommended method) 😁
from kratos.
菜鸟咨询:能否进行配置文件没配置的部分给默认值 (比较推荐的方式) 😁
我的做法:(不过用了泛型,可能会有点性能损耗,我自己测了下,损耗不大。结合实际并发情况使用吧。)
相关包代码:
package values
// If returns trueVal if condition is true, otherwise falseVal
//
// Example:
//
// If(true, "foo", "bar") // "foo"
// If(false, "foo", "bar") // "bar"
func If[T any](condition bool, trueVal T, falseVal T) T {
if condition {
return trueVal
}
return falseVal
}
// With calls the given callbacks with the given value then return the value.
//
// Example:
//
// With("foo", func(s string) string {
// return s + "bar"
// }, func(s string) string {
// return s + "baz"
// }) // "foobarbaz"
func With[T any](value T, callbacks ...func(T) T) T {
for _, callback := range callbacks {
if callback != nil {
value = callback(value)
}
}
return value
}
type Proxy[T any] struct {
value T
}
func NewProxy[T any](value T) *Proxy[T] {
return &Proxy[T]{
value: value,
}
}
func (p *Proxy[T]) When(condition bool, callbacks ...func(T) T) *Proxy[T] {
if condition {
return p.With(callbacks...)
}
return p
}
func (p *Proxy[T]) Value() T {
return p.value
}
from kratos.
注入到
context.Context
。我现在的做法(参考):
package main import ( "context" "fmt" "github.com/go-kratos/kratos/v2" "github.com/go-kratos-ecosystem/components/v2/config" "github.com/go-kratos-ecosystem/components/v2/env" "github.com/go-kratos-ecosystem/components/v2/provider" "github.com/go-kratos-ecosystem/components/v2/timezone" ) type Config struct { Host string } func main() { ctx, err := provider.Pipe(context.Background(), // 注入到 context 中 config.Provider(&Config{ Host: "localhost", }), // 注入其他的 Provider timezone.Provider(timezone.Local("Asia/Shanghai")), env.Provider(env.Prod), ) if err != nil { panic(err) } app := kratos.New( kratos.Context(ctx), kratos.Server(), ) if err := app.Run(); err != nil { panic(err) } } // DemoService is a demo service. func DemoService(ctx context.Context) error { cfg, ok := config.FromContext[*Config](ctx) if !ok { return fmt.Errorf("config not found") } _ = cfg return nil }参考资料:
This is not a good proposal and should not be provided by the config package
from kratos.
注入到
context.Context
。
我现在的做法(参考):package main import ( "context" "fmt" "github.com/go-kratos/kratos/v2" "github.com/go-kratos-ecosystem/components/v2/config" "github.com/go-kratos-ecosystem/components/v2/env" "github.com/go-kratos-ecosystem/components/v2/provider" "github.com/go-kratos-ecosystem/components/v2/timezone" ) type Config struct { Host string } func main() { ctx, err := provider.Pipe(context.Background(), // 注入到 context 中 config.Provider(&Config{ Host: "localhost", }), // 注入其他的 Provider timezone.Provider(timezone.Local("Asia/Shanghai")), env.Provider(env.Prod), ) if err != nil { panic(err) } app := kratos.New( kratos.Context(ctx), kratos.Server(), ) if err := app.Run(); err != nil { panic(err) } } // DemoService is a demo service. func DemoService(ctx context.Context) error { cfg, ok := config.FromContext[*Config](ctx) if !ok { return fmt.Errorf("config not found") } _ = cfg return nil }参考资料:
This is not a good proposal and should not be provided by the config package这不是一个好的建议,不应由配置包提供
这个确实,适合用工具或者有个类似 bootstrap 统一进行初始化的包实现好点。
from kratos.
can't reading bool value from environment config
from kratos.
希望支持byte序列化,因为配置有从配置中心读取到程序中,目前的Scan方法只能读取文件path
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
We hope to support byte serialization because the configuration is read from the configuration center into the program. The current Scan method can only read the file path.
from kratos.
Load 支持多次调用,因为有时候比如用配置中心,先拿到本地的配置然后才会连上配置中心接着 load
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Load supports multiple calls, because sometimes, for example, when using the configuration center, you first get the local configuration and then connect to the configuration center and then load
from kratos.
希望支持先 path 然后 在 scan , 类似 https://github.com/go-micro/go-micro/blob/master/config/config.go#L82
config.Get("cos", "user", "domain").Scan(&domain)
from kratos.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Hope to support path first and then scan, similar to https://github.com/go-micro/go-micro/blob/master/config/config.go#L82
config.Get("cos", "user", "domain").Scan(&domain)
from kratos.
1.Need to load the configuration from the config center and write it to a local configuration file, such as configmap, in case the config center goes down and the service doesn't start?
2. Multi-configuration source loading priority/order
from kratos.
Related Issues (20)
- [Feature] log Helper sprint, sprintf is executed before Filter Level, the performance consumption is very high HOT 3
- [Question]Transaction nested conflict stuck HOT 3
- [Feature] consule register need suport tags[] HOT 2
- When the App stops, the ctx in the afterStop callback is not available HOT 3
- [Question] How to return other Status Code in a successful HTTP request? HOT 7
- [Feature] Add Unwrap to custom response writer. HOT 3
- [Feature] replace kratos metrics with otel metrics HOT 3
- [The modification of header file information of http response does not take effect] ctx.Header().Set("Content-Type", "application/octet-stream") HOT 5
- [Question] How to return a custom response json? HOT 1
- Package version dependency issue HOT 4
- go generate ./...failed HOT 5
- [Feature]Add svrType related fields in proto to protoc-gen-go-http and http transport HOT 3
- proto file used to build the api document reported an error HOT 1
- consul watch, the server is offline and will not receive any notification HOT 6
- [Feature] Add NewClient method to gRPC Client HOT 3
- [Question] DDD的最佳实践方式?包括CQRS、Clean Architecture、六边形结构 HOT 5
- [Question]请教下kratos如何定义支持上传文件接口? HOT 2
- metrics statistics and usage issues [Question] HOT 5
- `stream` response in proto failed to generate http client HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kratos.