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

Re-export FmtText as a deprecated constant. #666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion expfmt/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ResponseFormat(h http.Header) Format {
if v, ok := params["version"]; ok && v != TextVersion {
return fmtUnknown
}
return fmtText
return FmtText
}

return fmtUnknown
Expand Down
6 changes: 3 additions & 3 deletions expfmt/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ func testDiscriminatorHTTPHeader(t testing.TB) {
},
{
input: map[string]string{"Content-Type": `text/plain; version=0.0.4`},
output: fmtText,
output: FmtText,
},
{
input: map[string]string{"Content-Type": `text/plain`},
output: fmtText,
output: FmtText,
},
{
input: map[string]string{"Content-Type": `text/plain; version=0.0.3`},
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestTextDecoderWithBufioReader(t *testing.T) {

var decoded bool
r := bufio.NewReader(strings.NewReader(example))
dec := NewDecoder(r, fmtText)
dec := NewDecoder(r, FmtText)
for {
var mf dto.MetricFamily
if err := dec.Decode(&mf); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions expfmt/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func Negotiate(h http.Header) Format {
}
}
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
return fmtText + escapingScheme
return FmtText + escapingScheme
}
}
return fmtText + escapingScheme
return FmtText + escapingScheme
}

// NegotiateIncludingOpenMetrics works like Negotiate but includes
Expand Down Expand Up @@ -118,7 +118,7 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
}
}
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
return fmtText + escapingScheme
return FmtText + escapingScheme
}
if ac.Type+"/"+ac.SubType == OpenMetricsType && (ver == OpenMetricsVersion_0_0_1 || ver == OpenMetricsVersion_1_0_0 || ver == "") {
switch ver {
Expand All @@ -129,7 +129,7 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
}
}
}
return fmtText + escapingScheme
return FmtText + escapingScheme
}

// NewEncoder returns a new encoder based on content type negotiation. All
Expand Down
4 changes: 2 additions & 2 deletions expfmt/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestEncode(t *testing.T) {
// 4: Untyped fmtText
{
metric: metric1,
format: fmtText,
format: FmtText,
expOut: `# TYPE foo_metric untyped
foo_metric 1.234
`,
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestEscapedEncode(t *testing.T) {

buff.Reset()

textEncoder := NewEncoder(&buff, fmtText)
textEncoder := NewEncoder(&buff, FmtText)
err = textEncoder.Encode(metric)
if err != nil {
t.Errorf("unexpected error during encode: %s", err.Error())
Expand Down
13 changes: 10 additions & 3 deletions expfmt/expfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ const (
// The Content-Type values for the different wire protocols. Note that these
// values are now unexported. If code was relying on comparisons to these
// constants, instead use FormatType().
fmtUnknown Format = `<unknown>`
fmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
fmtUnknown Format = `<unknown>`

// FmtText defines a Content-Type for the basic plaintext protocol.
//
// Deprecated: FmtText should not be used directly in code. With the addition
// of the escaping term, format strings now have many permutations and doing
// direct string comparisons of formats is not reliable. Instead, users should
// call FormatType and compare the result against the possible enum values.
FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
fmtProtoDelim Format = protoFmt + ` encoding=delimited`
fmtProtoText Format = protoFmt + ` encoding=text`
fmtProtoCompact Format = protoFmt + ` encoding=compact-text`
Expand Down Expand Up @@ -85,7 +92,7 @@ func NewFormat(t FormatType) Format {
case TypeProtoText:
return fmtProtoText
case TypeTextPlain:
return fmtText
return FmtText
case TypeOpenMetrics:
return fmtOpenMetrics_1_0_0
default:
Expand Down
2 changes: 1 addition & 1 deletion expfmt/expfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestToFormatType(t *testing.T) {
expected: TypeOpenMetrics,
},
{
format: fmtText,
format: FmtText,
expected: TypeTextPlain,
},
{
Expand Down