github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/manifest/util.go (about) 1 // Copyright 2018 The WPT Dashboard Project. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package manifest 6 7 import ( 8 "encoding/json" 9 10 "github.com/web-platform-tests/wpt.fyi/shared" 11 ) 12 13 // Filter filters items in the the given manifest JSON, omitting anything that isn't an 14 // item which has a URL beginning with one of the given paths. 15 func Filter(body []byte, paths []string) (result []byte, err error) { 16 var parsed *shared.Manifest 17 if err = json.Unmarshal(body, &parsed); err != nil { 18 return nil, err 19 } 20 if parsed, err = parsed.FilterByPath(paths...); err != nil { 21 return nil, err 22 } 23 body, err = json.Marshal(parsed) 24 if err != nil { 25 return nil, err 26 } 27 28 return body, nil 29 }