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