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

Is it an option an implementing Encoder.CompactComments(bool) method? #540

Closed
Felixoid opened this issue May 11, 2021 · 6 comments
Closed
Labels
feature Issue asking for a new feature in go-toml.

Comments

@Felixoid
Copy link
Contributor

Felixoid commented May 11, 2021

Hello. I continue to playing around with the library.

I've found, that with the current code it's impossible to get the compact config output when comments are used. Each comment produces an additional line and it's difficult to overview the config. As a workaround, I use the following snippet, but it removes spaces between sections too:

out := strings.Replace(buf.String(), "\n", "", 1)
out = strings.ReplaceAll(out, "\n\n", "\n")

So, I have now the config like

[common]

# general listener
listen = ":9090"
max-cpu = 1

# limit number of results from find query, 0=unlimited
max-metrics-in-find-answer = 0

# limit numbers of queried metrics per target in /render requests, 0 or negative = unlimited
max-metrics-per-target = 15000

# daemon will return the freed memory to the OS when it>0
memory-return-interval = "0s"

# listener to serve /debug/pprof requests. '-pprof' argument overrides it
pprof-listen = ""

# daemon returns empty response if query matches any of regular expressions
# target-blacklist = []

[clickhouse]

# see https://clickhouse.tech/docs/en/interfaces/http
url = "http://localhost:8123"

# total timeout to fetch data
data-timeout = "1m0s"
index-table = "graphite_index"
index-use-daily = true
index-reverse-depth = 1

# total timeout to fetch series list from index
index-timeout = "1m0s"

# 'tagged' table from carbon-clickhouse, required for seriesByTag
tagged-table = "graphite_tagged"

# or how long the daemon will query tags during autocomplete
tagged-autocomplete-days = 7

# old index table, DEPRECATED, see description in doc/config.md
# tree-table = ""
# reverse-tree-table = ""
# date-tree-table = ""
# date-tree-table-version = 0
# tree-timeout = "0s"

# is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU
# tag-table = ""

# add extra prefix (directory in graphite) for all metrics, w/o trailing dot
extra-prefix = ""

# TCP connection timeout
connect-timeout = "1s"

# will be removed in 0.14
# data-table = ""
# rollup-conf = "auto"

# max points per metric when internal-aggregation=true
max-data-points = 1048576

# ClickHouse-site aggregation, see doc/aggregation.md
internal-aggregation = true

And I'd like to have it

[common]
# general listener
listen = ":9090"
max-cpu = 1
# limit number of results from find query, 0=unlimited
max-metrics-in-find-answer = 0
# limit numbers of queried metrics per target in /render requests, 0 or negative = unlimited
max-metrics-per-target = 15000
# daemon will return the freed memory to the OS when it>0
memory-return-interval = "0s"
# listener to serve /debug/pprof requests. '-pprof' argument overrides it
pprof-listen = ""
# daemon returns empty response if query matches any of regular expressions
# target-blacklist = []

[clickhouse]
# see https://clickhouse.tech/docs/en/interfaces/http
url = "http://localhost:8123"
# total timeout to fetch data
data-timeout = "1m0s"
index-table = "graphite_index"
index-use-daily = true
index-reverse-depth = 1
# total timeout to fetch series list from index
index-timeout = "1m0s"
# 'tagged' table from carbon-clickhouse, required for seriesByTag
tagged-table = "graphite_tagged"
# or how long the daemon will query tags during autocomplete
tagged-autocomplete-days = 7
# old index table, DEPRECATED, see description in doc/config.md
# tree-table = ""
# reverse-tree-table = ""
# date-tree-table = ""
# date-tree-table-version = 0
# tree-timeout = "0s"
# is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU
# tag-table = ""
# add extra prefix (directory in graphite) for all metrics, w/o trailing dot
extra-prefix = ""
# TCP connection timeout
connect-timeout = "1s"
# will be removed in 0.14
# data-table = ""
# rollup-conf = "auto"
# max points per metric when internal-aggregation=true
max-data-points = 1048576
# ClickHouse-site aggregation, see doc/aggregation.md
internal-aggregation = true

I've found a place that should be patched, https://github.com/pelletier/go-toml/blob/c893dbf/tomltree_write.go#L417

My question is would you consider the Encoder.CompactComments(bool) method to trigger the compact output for comment-lines?

upd: well, I already have created #541

@pelletier
Copy link
Owner

Hi! I'm happy to merge that feature to go-toml v1. I'm not sure yet if I want to include it in go-toml v2: my current thinking has been to minimize the amount of options on encoding but instead provide the tools to write an encoder that tailor to specific needs.

@pelletier pelletier added the feature Issue asking for a new feature in go-toml. label May 12, 2021
@pelletier
Copy link
Owner

Merged!

@Felixoid
Copy link
Contributor Author

Thank you, I am looking forward to seeing how the v2 will look like. And the v1 looks like a charm to me!

@Felixoid
Copy link
Contributor Author

Felixoid commented Jun 5, 2021

Hey Thomas @pelletier, sorry for disturbing you, but can you, maybe, release 1.9.2 version with this feature, please? I already use it and it would be very useful to have it stable

@pelletier
Copy link
Owner

Sorry, completely forgot! Let me do it now.

@pelletier
Copy link
Owner

Done https://github.com/pelletier/go-toml/releases/tag/v1.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue asking for a new feature in go-toml.
Projects
None yet
Development

No branches or pull requests

2 participants