forked from CaptainCodeman/prpl-server-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.go
39 lines (31 loc) · 916 Bytes
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package prpl
import (
"os"
"encoding/json"
)
// Manifest is the preload manifest map where each value,
// being a collection of resources to be preloaded,
// keyed by a serving URL path which requires those resources.
type Manifest map[string]map[string]AssetOpt
// AssetOpt defines a single resource options.
type AssetOpt struct {
// Type is the resource type
Type string `json:"type,omitempty"`
// Weight is not used in the HTTP/2 preload spec
// but some HTTP/2 servers, while implementing stream priorities,
// could benefit from this manifest format as well.
Weight uint8 `json:"weight,omitempty"`
}
// ReadManifest reads a push manifest from name file.
func ReadManifest(name string) (Manifest, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
var m Manifest
if err := json.NewDecoder(f).Decode(&m); err != nil {
return nil, err
}
return m, nil
}