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

Complex config support: Implement Block.Merge(), improve string representation. #3

Merged
merged 8 commits into from
May 18, 2020

Conversation

octo
Copy link

@octo octo commented May 18, 2020

The IsString() method is identical to "collectd.org/meta".Entry.IsString.

Block.Merge() is going to be needed by the plugin package.

octo added 4 commits May 18, 2020 10:37
The Value.String() method returns a string only, implemeting the fmt.Stringer
interface.

Previously, a string value `StringValue("test")` would print as:

  `0 "test" 0 false`

With this change, it prints as:

  `test`

Users of the package can use the new Value.IsString() method to check if a
value really is a string. This is clumsy, but in reality users will more likely
use Value.Interface() and a type switch.

This change also implements the fmt.GoStringer interface for the Value type.
With this, if the above string value is printed with `%#v`, it will produce:

  `config.StringValue("test")`

Consider these test outputs to see how these changes improve the output:

  config_test.go:397: block = config.Block{Key:"Plugin", Values:[]config.Value{config.StringValue("test")}, Children:[]config.Block(nil)}
  config_test.go:400: block.Merge() = blocks differ: got {key:SomethingElse values:[test]}, want {key:Plugin, values:[test]}, want error false
  config_test.go:407: other block = config.Block{Key:"SomethingElse", Values:[]config.Value{config.StringValue("test")}, Children:[]config.Block(nil)}
octo added 4 commits May 18, 2020 13:20
…ock.

I think this was a left-over from the original approach that unmarshalled
before calling the callback.
wrap_configure_callback() needs to be able to modify the structs stored in
that map. The most intuitive way to do that is by storing pointers in the
map.
@octo
Copy link
Author

octo commented May 18, 2020

Sorry for trespassing – I got carried away since this was so close ;)

I tested this with collectd/go-plugins#1 and it appears to work \o/

@alowde
Copy link
Owner

alowde commented May 18, 2020

Haha, can't really trespass on your own project :). I've read through the code but there's nothing I could suggest to improve, looks good.

@alowde alowde merged commit 984d4df into alowde:plugin/complex_config_callback_v2 May 18, 2020
@octo octo deleted the pr/63 branch May 19, 2020 09:38
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.

2 participants