Comments (3)
FYSA @ashrayjain
from witchcraft-go-server.
Thought about this further after our in-person discussion. I think the decision here stems on how opinionated we want to be in terms of how we deal with configuration.
As you point out in this issue, right now witchcraft is opinionated in its use of yaml.Unmarshal
from go-yaml/yaml (aka gopkg.in/yaml.v2) to perform config unmarshaling. It's probably not unreasonable to allow this function to be configured by allowing the user to specify a custom func([]byte, interface{}) error
used in all places where config is unmarshaled (and default the value to yaml.Unmarshal
). This would allow the use of other YAML libraries/custom functionality as outlined here. However, because this generically plugs the unmarshal, it would also allow clients to unmarshal config as JSON or whatever else they want as well. Probably not a huge issue, but just worth flagging that allowing configuration of the Unmarshal
behavior does technically allow a lot more to be configured. We would probably need to caveat that, in general, witchcraft
configuration will be written in a manner that assumes the behavior of yaml.Unmarshal
, so if the user provides their own implementation they are potentially responsible for supporting all of its behavior (tags such as ,inline
, etc.).
If we decide that the usage of yaml.Unmarshal
is one of the opinions of this library (which is also somewhat the case based on the default tags format we use for base config), then I don't think we should allow this to be configured. In this scenario, it's still possible to perform custom operations like setting/loading defaults for config, but it has to be structured as part of the yaml.Unmarshal
or as a specialized config byte provider.
Right now I'm leaning slightly towards the first approach, but @bmoylan curious to hear your thoughts/opinion.
from witchcraft-go-server.
Concretely, if there's some function like structfields.SetToDefaults
(analogous to https://github.com/creasty/defaults), then the approaches described above would be:
WithConfigUnmarshalFunction(func(data []byte, v interface{}) error {
if err := structfields.SetToDefaults(v); err != nil {
return err
}
return yaml.Unmarshal(data, v)
})
vs. implementing something like:
func (cfg *AppInstallConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := structfields.SetToDefaults(cfg); err != nil {
return err
}
type RawAppInstallConfig AppInstallConfig
rawCfg := RawAppInstallConfig(*cfg)
if err := unmarshal(&rawCfg); err != nil {
return err
}
*cfg = AppInstallConfig(rawCfg)
return nil
}
For the install and runtime structs.
from witchcraft-go-server.
Related Issues (20)
- Runtime config refreshable produces zero value if cannot parse yaml
- pprof/goroutine returns 404 HOT 2
- Add a default health check for a sliding window of events HOT 1
- TestNewInflightLimitMiddleware test flakes
- Separate out trace sampling for application routes and management routes
- Allow selecting which go metrics you care about to emit HOT 4
- Default server/client metrics too verbose, no option to trim down HOT 10
- log canceled request as 499 instead of 500 HOT 8
- Ability to shutdown server with error HOT 3
- Reduce default trace rate to 1%
- 404s do not produce request logs
- Opt-in diagnostic log upon turning unhealthy HOT 5
- Improved panic logging
- Liveness endpoint should return non-empty JSON object
- Metric loggers should emit 0 value before regular value for certain metric types HOT 1
- connection metrics
- Encrypted values in configuration should be decoded while maintaining YAML structure
- RouteHandlerMiddleware unwieldy for endpoint-specific handling
- Missing pprof routes
- Library equivalent to Java's ManagedScheduledTask
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 witchcraft-go-server.