MCPcopy
hub / github.com/caddyserver/caddy / RemoveMetaFields

Function RemoveMetaFields

admin.go:1343–1354  ·  view source on GitHub ↗

RemoveMetaFields removes meta fields like "@id" from a JSON message by using a simple regular expression. (An alternate way to do this would be to delete them from the raw, map[string]any representation as they are indexed, then iterate the index we made and add them back after encoding as JSON, but

(rawJSON []byte)

Source from the content-addressed store, hash-verified

1341// representation as they are indexed, then iterate the index we made
1342// and add them back after encoding as JSON, but this is simpler.)
1343func RemoveMetaFields(rawJSON []byte) []byte {
1344 return idRegexp.ReplaceAllFunc(rawJSON, func(in []byte) []byte {
1345 // matches with a comma on both sides (when "@id" property is
1346 // not the first or last in the object) need to keep exactly
1347 // one comma for correct JSON syntax
1348 comma := []byte{','}
1349 if bytes.HasPrefix(in, comma) && bytes.HasSuffix(in, comma) {
1350 return comma
1351 }
1352 return []byte{}
1353 })
1354}
1355
1356// AdminHandler is like http.Handler except ServeHTTP may return an error.
1357//

Callers 1

unsyncedDecodeAndRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected