Skip to content
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

config and log rearchitect #177

Merged
merged 6 commits into from
Aug 31, 2021
Merged

config and log rearchitect #177

merged 6 commits into from
Aug 31, 2021

Conversation

Reasno
Copy link
Member

@Reasno Reasno commented Aug 24, 2021

This PR intends to build easy-to-use implementations on top of easy-to-extend interfaces, and bring the value of both to the package core.

The interface is easy to extend if there are very few methods. However, an interface with very few methods can be cumbersome to use.

Easy to extend:

type ConfigUnmarshaler interface {
	Unmarshal(path string, o interface{}) error
}

type Logger interface {
    Log(keyvals ...interface{}) error
}

Easy to use:

type ConfigAccessor interface {
	ConfigUnmarshaler

	String(string) string
	Int(string) int
	Strings(string) []string
	Bool(string) bool
	Get(string) interface{}
	Float64(string) float64
}

type LevelLogger interface {
	Logger
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Err(args ...interface{})
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errf(template string, args ...interface{})
	Debugw(msg string, fields ...interface{})
	Infow(msg string, fields ...interface{})
	Warnw(msg string, fields ...interface{})
	Errw(msg string, fields ...interface{})
}

This PR allows user to upgrade the easy-to-extend interfaces to easy-to-use interfaces with one wrapped method call:

func WithAccessor(unmarshaler contract.ConfigUnmarshaler) contract.ConfigAccessor
func WithLevel(logger log.Logger) LevelLogger

So implementors only need to satisfy the minimum interfaces, but consumers are free to use the richer API provided by upgraded interfaces.

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #177 (debb5ee) into master (4cccba0) will increase coverage by 0.02%.
The diff coverage is 83.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
+ Coverage   80.50%   80.53%   +0.02%     
==========================================
  Files          91       91              
  Lines        3273     3308      +35     
==========================================
+ Hits         2635     2664      +29     
- Misses        463      469       +6     
  Partials      175      175              
Impacted Files Coverage Δ
default_config.go 78.94% <ø> (ø)
leader/dependency.go 83.72% <ø> (ø)
otes/dependency.go 80.32% <ø> (ø)
otetcd/dependency.go 97.22% <ø> (ø)
otgorm/dependency.go 91.89% <ø> (ø)
otkafka/dependency.go 86.36% <ø> (ø)
otmongo/dependency.go 85.71% <ø> (ø)
otredis/dependency.go 84.41% <ø> (ø)
ots3/dependency.go 67.39% <ø> (ø)
logging/log.go 40.50% <28.57%> (+1.06%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cccba0...debb5ee. Read the comment docs.

@Reasno Reasno requested review from GGXXLL and lingwei0604 and removed request for GGXXLL August 24, 2021 07:33
Copy link
Member

@lingwei0604 lingwei0604 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Reasno Reasno added this to the v0.9.0 milestone Aug 25, 2021
@Reasno Reasno merged commit 3c8e3d2 into master Aug 31, 2021
@Reasno Reasno deleted the configunmarshaler branch August 31, 2021 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants