-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feature/support labels #26
Conversation
…ath":"value2" to "my.config: path:value, secondpath:value2. Its hard to describe in git commit, but Im flatting the config in a yaml way
* "feature/support-labels" * Transforming configs like "my.config.path":"value, "my.config.secondpath":"value2" to "my.config: path:value, secondpath:value2. Its hard to describe in git commit, but Im flatting the config in a yaml way
client.go
Outdated
@@ -4,11 +4,12 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
"github.com/Piszmog/cfservices" | |||
"golang.org/x/oauth2/clientcredentials" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this. For this project, import formatting uses gofmt
instead of goimports
.
Hopefully imports formats get figured out (see #37719)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so if I understand well, goimports is a superset of gofmt. gofmt format struct, field and whatnot while goimports add format for imports?
I've manually reverted the import to what they were, I can't seem to use gofmt to reformat struct.
My understanding of reading on the web is that goimports is just better than gofmt.
@@ -3,12 +3,13 @@ package cloudconfigclient_test | |||
import ( | |||
"context" | |||
"errors" | |||
"github.com/Piszmog/cloudconfigclient/v2" | |||
"github.com/stretchr/testify/require" | |||
"golang.org/x/oauth2/clientcredentials" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -52,6 +56,18 @@ func (s *Source) HandlePropertySources(handler PropertySourceHandler) { | |||
} | |||
} | |||
|
|||
func (s *Source) Get(key string, defaultValue string) interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Also this is where the Map I've added could be used. If we use the map to retrieve the config value, we would have complexity O(1) instead of O(n) on every search right. Therefore I think this lib should use the Map as it's core.
configuration.go
Outdated
func (s *Source) Get(key string, defaultValue string) interface{} { | ||
for _, propertySource := range s.PropertySources { | ||
for _key, value := range propertySource.Source { | ||
fmt.Printf("key=%s, value=%v\n", _key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the library should avoid unnecessary logging/noise. Please remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
configuration.go
Outdated
@@ -52,6 +56,18 @@ func (s *Source) HandlePropertySources(handler PropertySourceHandler) { | |||
} | |||
} | |||
|
|||
func (s *Source) Get(key string, defaultValue string) interface{} { | |||
for _, propertySource := range s.PropertySources { | |||
for _key, value := range propertySource.Source { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename _key
to sourceKey
to make it more clear. I was confused at first what _key
was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
go.mod
Outdated
@@ -1,4 +1,4 @@ | |||
module github.com/Piszmog/cloudconfigclient/v2 | |||
module github.com/duvalhub/cloudconfigclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1,8 +1,11 @@ | |||
package cloudconfigclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General Formatting needs to be done. Please use gofmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
So the flatness is from the Config Server itself. The key values are in a Properties format. Looking at the code and your initial PR comment, I would recommend a function that converts Properties format to the structure that you want, vs what you have now. For example, func (p *PropertySource) FromProperties() map[string]interface{} {
...
} This is where we would unflatten the key values |
return dest | ||
} | ||
|
||
type BasicAuthTransport struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bit and down seems redundant and is more application specific implementation of this library. I do not think it belong in this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this BasicAuthTransport because this lib does not support Basic Authentication with ConfigServer (unless I missed something). This bit of code handle that.
My idea is that the returned format from Config Server is a bit useless. What gives to loop through all PropertySource when we can access the value straight in a map. It's also less efficient. Like the function Also my plan (or my used case) is to be able to map a config key to a struct, like this : |
client.go
Outdated
@@ -4,11 +4,12 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
"github.com/Piszmog/cfservices" | |||
"golang.org/x/oauth2/clientcredentials" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so if I understand well, goimports is a superset of gofmt. gofmt format struct, field and whatnot while goimports add format for imports?
I've manually reverted the import to what they were, I can't seem to use gofmt to reformat struct.
My understanding of reading on the web is that goimports is just better than gofmt.
@@ -3,12 +3,13 @@ package cloudconfigclient_test | |||
import ( | |||
"context" | |||
"errors" | |||
"github.com/Piszmog/cloudconfigclient/v2" | |||
"github.com/stretchr/testify/require" | |||
"golang.org/x/oauth2/clientcredentials" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -52,6 +56,18 @@ func (s *Source) HandlePropertySources(handler PropertySourceHandler) { | |||
} | |||
} | |||
|
|||
func (s *Source) Get(key string, defaultValue string) interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Also this is where the Map I've added could be used. If we use the map to retrieve the config value, we would have complexity O(1) instead of O(n) on every search right. Therefore I think this lib should use the Map as it's core.
configuration.go
Outdated
@@ -52,6 +56,18 @@ func (s *Source) HandlePropertySources(handler PropertySourceHandler) { | |||
} | |||
} | |||
|
|||
func (s *Source) Get(key string, defaultValue string) interface{} { | |||
for _, propertySource := range s.PropertySources { | |||
for _key, value := range propertySource.Source { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
configuration.go
Outdated
func (s *Source) Get(key string, defaultValue string) interface{} { | ||
for _, propertySource := range s.PropertySources { | ||
for _key, value := range propertySource.Source { | ||
fmt.Printf("key=%s, value=%v\n", _key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return dest | ||
} | ||
|
||
type BasicAuthTransport struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this BasicAuthTransport because this lib does not support Basic Authentication with ConfigServer (unless I missed something). This bit of code handle that.
configuration.go
Outdated
return dest | ||
} | ||
|
||
func insertInMapRecursion(s []string, value interface{}, dest map[string]interface{}) map[string]interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insertInMap and insertInMapRecursion have the same functional logic. We should keep one of the two.
go.mod
Outdated
@@ -1,4 +1,4 @@ | |||
module github.com/Piszmog/cloudconfigclient/v2 | |||
module github.com/duvalhub/cloudconfigclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Hi, sorry for taking a long time to get back to you on this. I have add the functionality to unmarshal the See #27 for an example |
Changes Description
Added support for labels. A spring config server path is "app/profiles/label" . https://cloud.spring.io/spring-cloud-config/reference/html/#_locating_remote_configuration_resources
Flatting the configuration in a "map" way.
From
to
Associated Issues
I needed the labels and a get_property function to retrieve "my.config1" value for example.
Affected Files
See commits
Unit Tests Changed or Added
I've added tests for all files
Let me know if this interested you. I'll will probably add more functionality to this lib as I go along.