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

expvar: returned are not json string when using Publish() #18000

Closed
mohanson opened this issue Nov 21, 2016 · 1 comment
Closed

expvar: returned are not json string when using Publish() #18000

mohanson opened this issue Nov 21, 2016 · 1 comment

Comments

@mohanson
Copy link

What version of Go are you using (go version)?

go version go1.6.1 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\root\gopath
set GORACE=
set GOROOT=D:\Program Files\Go
set GOTOOLDIR=D:\Program Files\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

What did you do?

package main

import (
	"expvar"
	"net/http"
	"time"
)

var origin = time.Now()

func init() {
	expvar.Publish("origin", origin)
}

func main() {
	go http.ListenAndServe("127.0.0.1:8080", nil)
	select{}
}

What did you expect to see?

curl http://127.0.0.1:8080/debug/vars | python -m json.tool returned a JSON string and the KV of "origin" is "origin": "2016-11-2123:19:50.3948635+0800CST"

What did you see instead?

curl http://127.0.0.1:8080/debug/vars | python -m json.tool raise a error because the returned output are not a JSON string. The KV of "origin" is "origin": 2016-11-21 23:16:58.4657459 +0800 CST (missing quote)

@bradfitz
Copy link
Contributor

This is your responsibility. The docs were clarified recently in 2a12035 :

commit 2a12035f8ec18f0a577853fda78faf2826397131
Author: Scott Bell <scott@sctsm.com>
Date:   Wed May 18 18:44:46 2016 -0700

    expvar: slightly expand documentation for Var's String method
    
    Fixes #15088.
    
    Change-Id: I7727829a4062e15c0e5e3beff4d0bfc1fa327b0f
    Reviewed-on: https://go-review.googlesource.com/23232
    Reviewed-by: Andrew Gerrand <adg@golang.org>
    Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>

@golang golang locked and limited conversation to collaborators Nov 21, 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

3 participants