MCPcopy Create free account
hub / github.com/prometheus/common / FormatType

Method FormatType

expfmt/expfmt.go:155–201  ·  view source on GitHub ↗

FormatType deduces an overall FormatType for the given format.

()

Source from the content-addressed store, hash-verified

153
154// FormatType deduces an overall FormatType for the given format.
155func (f Format) FormatType() FormatType {
156 toks := strings.Split(string(f), ";")
157 params := make(map[string]string)
158 for i, t := range toks {
159 if i == 0 {
160 continue
161 }
162 args := strings.Split(t, "=")
163 if len(args) != 2 {
164 continue
165 }
166 params[strings.TrimSpace(args[0])] = strings.TrimSpace(args[1])
167 }
168
169 switch strings.TrimSpace(toks[0]) {
170 case ProtoType:
171 if params["proto"] != ProtoProtocol {
172 return TypeUnknown
173 }
174 switch params["encoding"] {
175 case "delimited":
176 return TypeProtoDelim
177 case "text":
178 return TypeProtoText
179 case "compact-text":
180 return TypeProtoCompact
181 default:
182 return TypeUnknown
183 }
184 case OpenMetricsType:
185 if params["charset"] != "utf-8" {
186 return TypeUnknown
187 }
188 return TypeOpenMetrics
189 case "text/plain":
190 v, ok := params["version"]
191 if !ok {
192 return TypeTextPlain
193 }
194 if v == TextVersion {
195 return TypeTextPlain
196 }
197 return TypeUnknown
198 default:
199 return TypeUnknown
200 }
201}
202
203// ToEscapingScheme returns an EscapingScheme depending on the Format. Iff the
204// Format contains a escaping=allow-utf-8 term, it will select NoEscaping. If a valid

Callers 4

TestToFormatTypeFunction · 0.80
NegotiateAcceptFunction · 0.80
NewEncoderFunction · 0.80
NewDecoderFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestToFormatTypeFunction · 0.64