Skip to content

proposal: add accessors to the expvar concrete types #15815

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

Closed
FiloSottile opened this issue May 24, 2016 · 6 comments
Closed

proposal: add accessors to the expvar concrete types #15815

FiloSottile opened this issue May 24, 2016 · 6 comments

Comments

@FiloSottile
Copy link
Contributor

There is no good way to export expvar values. One can get as far as type-switching, but then the only method left is still String(), which has to be parsed by looking at how it's serialized in the expvar source.

As an example, I'd rather not have written this: https://github.com/thecodearchive/gitarchive/blob/4027007d21f759a1282c67ae44e6df099c208da4/metrics/influxdb.go#L31-L47

I propose adding the following accessor methods:

func (*Float) Value() float64
func (*Int) Value() int64
func (*String) Value() string // returns the unquoted version
func (Func) Value() interface{}

I considered calling them Int(), Float(), etc. but then String() would clash.

@ianlancetaylor
Copy link
Contributor

I'm not really opposed to the idea, but it's not clear to me why you did write that code. Why not just export the variable as strings? What advantage do you get by converting them to specific types?

@ianlancetaylor ianlancetaylor added this to the Proposal milestone May 24, 2016
@FiloSottile
Copy link
Contributor Author

FiloSottile commented May 24, 2016 via email

@bradfitz
Copy link
Contributor

I'm fine with this. Send a CL when Go 1.8 opens? Be sure to document the existing String.String method.

@adg
Copy link
Contributor

adg commented Aug 29, 2016

@FiloSottile let's do this! 😄

@FiloSottile
Copy link
Contributor Author

FiloSottile commented Aug 30, 2016 via email

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/30917 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants