Skip to content

Commit bb1fa18

Browse files
committed
Revert "Unexport Format strings"
This reverts commit 05d7387. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 8e3075b commit bb1fa18

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

expfmt/decode.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ func ResponseFormat(h http.Header) Format {
4545

4646
mediatype, params, err := mime.ParseMediaType(ct)
4747
if err != nil {
48-
return fmtUnknown
48+
return FmtUnknown
4949
}
5050

5151
const textType = "text/plain"
5252

5353
switch mediatype {
5454
case ProtoType:
5555
if p, ok := params["proto"]; ok && p != ProtoProtocol {
56-
return fmtUnknown
56+
return FmtUnknown
5757
}
5858
if e, ok := params["encoding"]; ok && e != "delimited" {
59-
return fmtUnknown
59+
return FmtUnknown
6060
}
61-
return fmtProtoDelim
61+
return FmtProtoDelim
6262

6363
case textType:
6464
if v, ok := params["version"]; ok && v != TextVersion {
65-
return fmtUnknown
65+
return FmtUnknown
6666
}
67-
return fmtText
67+
return FmtText
6868
}
6969

70-
return fmtUnknown
70+
return FmtUnknown
7171
}
7272

7373
// NewDecoder returns a new decoder based on the given input format.

expfmt/decode_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func TestProtoMultiMessageDecoder(t *testing.T) {
423423
}
424424

425425
buf := bytes.NewReader(data)
426-
decoder := NewDecoder(buf, fmtProtoDelim)
426+
decoder := NewDecoder(buf, FmtProtoDelim)
427427
var metrics []*dto.MetricFamily
428428
for {
429429
var mf dto.MetricFamily
@@ -448,27 +448,27 @@ func testDiscriminatorHTTPHeader(t testing.TB) {
448448
}{
449449
{
450450
input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="io.prometheus.client.MetricFamily"; encoding="delimited"`},
451-
output: fmtProtoDelim,
451+
output: FmtProtoDelim,
452452
},
453453
{
454454
input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="illegal"; encoding="delimited"`},
455-
output: fmtUnknown,
455+
output: FmtUnknown,
456456
},
457457
{
458458
input: map[string]string{"Content-Type": `application/vnd.google.protobuf; proto="io.prometheus.client.MetricFamily"; encoding="illegal"`},
459-
output: fmtUnknown,
459+
output: FmtUnknown,
460460
},
461461
{
462462
input: map[string]string{"Content-Type": `text/plain; version=0.0.4`},
463-
output: fmtText,
463+
output: FmtText,
464464
},
465465
{
466466
input: map[string]string{"Content-Type": `text/plain`},
467-
output: fmtText,
467+
output: FmtText,
468468
},
469469
{
470470
input: map[string]string{"Content-Type": `text/plain; version=0.0.3`},
471-
output: fmtUnknown,
471+
output: FmtUnknown,
472472
},
473473
}
474474

@@ -574,7 +574,7 @@ func TestTextDecoderWithBufioReader(t *testing.T) {
574574

575575
var decoded bool
576576
r := bufio.NewReader(strings.NewReader(example))
577-
dec := NewDecoder(r, fmtText)
577+
dec := NewDecoder(r, FmtText)
578578
for {
579579
var mf dto.MetricFamily
580580
if err := dec.Decode(&mf); err != nil {

expfmt/encode.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ func Negotiate(h http.Header) Format {
7777
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
7878
switch ac.Params["encoding"] {
7979
case "delimited":
80-
return fmtProtoDelim + escapingScheme
80+
return FmtProtoDelim + escapingScheme
8181
case "text":
82-
return fmtProtoText + escapingScheme
82+
return FmtProtoText + escapingScheme
8383
case "compact-text":
84-
return fmtProtoCompact + escapingScheme
84+
return FmtProtoCompact + escapingScheme
8585
}
8686
}
8787
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
88-
return fmtText + escapingScheme
88+
return FmtText + escapingScheme
8989
}
9090
}
91-
return fmtText + escapingScheme
91+
return FmtText + escapingScheme
9292
}
9393

9494
// NegotiateIncludingOpenMetrics works like Negotiate but includes
@@ -110,26 +110,26 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
110110
if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol {
111111
switch ac.Params["encoding"] {
112112
case "delimited":
113-
return fmtProtoDelim + escapingScheme
113+
return FmtProtoDelim + escapingScheme
114114
case "text":
115-
return fmtProtoText + escapingScheme
115+
return FmtProtoText + escapingScheme
116116
case "compact-text":
117-
return fmtProtoCompact + escapingScheme
117+
return FmtProtoCompact + escapingScheme
118118
}
119119
}
120120
if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") {
121-
return fmtText + escapingScheme
121+
return FmtText + escapingScheme
122122
}
123123
if ac.Type+"/"+ac.SubType == OpenMetricsType && (ver == OpenMetricsVersion_0_0_1 || ver == OpenMetricsVersion_1_0_0 || ver == "") {
124124
switch ver {
125125
case OpenMetricsVersion_1_0_0:
126-
return fmtOpenMetrics_1_0_0 + escapingScheme
126+
return FmtOpenMetrics_1_0_0 + escapingScheme
127127
default:
128-
return fmtOpenMetrics_0_0_1 + escapingScheme
128+
return FmtOpenMetrics_0_0_1 + escapingScheme
129129
}
130130
}
131131
}
132-
return fmtText + escapingScheme
132+
return FmtText + escapingScheme
133133
}
134134

135135
// NewEncoder returns a new encoder based on content type negotiation. All

expfmt/encode_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestEncode(t *testing.T) {
222222
// 1: Untyped ProtoDelim
223223
{
224224
metric: metric1,
225-
format: fmtProtoDelim,
225+
format: FmtProtoDelim,
226226
},
227227
// 2: Untyped fmtProtoCompact
228228
{
@@ -310,7 +310,7 @@ foo_metric 1.234
310310

311311
func TestEscapedEncode(t *testing.T) {
312312
var buff bytes.Buffer
313-
delimEncoder := NewEncoder(&buff, fmtProtoDelim+"; escaping=underscores")
313+
delimEncoder := NewEncoder(&buff, FmtProtoDelim+"; escaping=underscores")
314314
metric := &dto.MetricFamily{
315315
Name: proto.String("foo.metric"),
316316
Type: dto.MetricType_UNTYPED.Enum(),
@@ -346,7 +346,7 @@ func TestEscapedEncode(t *testing.T) {
346346

347347
buff.Reset()
348348

349-
compactEncoder := NewEncoder(&buff, fmtProtoCompact)
349+
compactEncoder := NewEncoder(&buff, FmtProtoCompact)
350350
err = compactEncoder.Encode(metric)
351351
if err != nil {
352352
t.Errorf("unexpected error during encode: %s", err.Error())
@@ -359,7 +359,7 @@ func TestEscapedEncode(t *testing.T) {
359359

360360
buff.Reset()
361361

362-
protoTextEncoder := NewEncoder(&buff, fmtProtoText)
362+
protoTextEncoder := NewEncoder(&buff, FmtProtoText)
363363
err = protoTextEncoder.Encode(metric)
364364
if err != nil {
365365
t.Errorf("unexpected error during encode: %s", err.Error())
@@ -372,7 +372,7 @@ func TestEscapedEncode(t *testing.T) {
372372

373373
buff.Reset()
374374

375-
textEncoder := NewEncoder(&buff, fmtText)
375+
textEncoder := NewEncoder(&buff, FmtText)
376376
err = textEncoder.Encode(metric)
377377
if err != nil {
378378
t.Errorf("unexpected error during encode: %s", err.Error())

expfmt/expfmt.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@ const (
3535
TextVersion = "0.0.4"
3636
ProtoType = `application/vnd.google.protobuf`
3737
ProtoProtocol = `io.prometheus.client.MetricFamily`
38-
protoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
38+
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
3939
OpenMetricsType = `application/openmetrics-text`
4040
OpenMetricsVersion_0_0_1 = "0.0.1"
4141
OpenMetricsVersion_1_0_0 = "1.0.0"
4242

43-
// The Content-Type values for the different wire protocols. Note that these
44-
// values are now unexported. If code was relying on comparisons to these
45-
// constants, instead use FormatType().
46-
fmtUnknown Format = `<unknown>`
47-
fmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
48-
fmtProtoDelim Format = protoFmt + ` encoding=delimited`
49-
fmtProtoText Format = protoFmt + ` encoding=text`
50-
fmtProtoCompact Format = protoFmt + ` encoding=compact-text`
51-
fmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
52-
fmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
43+
// The Content-Type values for the different wire protocols. Do not do direct
44+
// comparisons to these constants, instead use the comparison functions.
45+
FmtUnknown Format = `<unknown>`
46+
FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8`
47+
FmtProtoDelim Format = ProtoFmt + ` encoding=delimited`
48+
FmtProtoText Format = ProtoFmt + ` encoding=text`
49+
FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text`
50+
FmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8`
51+
FmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`
5352
)
5453

5554
const (
@@ -81,7 +80,7 @@ func NewFormat(t FormatType) Format {
8180
case TypeProtoCompact:
8281
return fmtProtoCompact
8382
case TypeProtoDelim:
84-
return fmtProtoDelim
83+
return FmtProtoDelim
8584
case TypeProtoText:
8685
return fmtProtoText
8786
case TypeTextPlain:

expfmt/expfmt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestToFormatType(t *testing.T) {
3232
expected: TypeProtoCompact,
3333
},
3434
{
35-
format: fmtProtoDelim,
35+
format: FmtProtoDelim,
3636
expected: TypeProtoDelim,
3737
},
3838
{

0 commit comments

Comments
 (0)