-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
53 lines (45 loc) · 1.21 KB
/
config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package prpl
import (
"bytes"
"io"
"os"
"encoding/json"
)
type (
// ProjectConfig is the subset of the polymer.json
// specification that we care about for serving.
// https://www.polymer-project.org/2.0/docs/tools/polymer-json
// https://github.com/Polymer/polymer-project-config/blob/master/src/index.ts
ProjectConfig struct {
Entrypoint string `json:"entrypoint"`
Shell string `json:"shell"`
Builds []BuildConfig `json:"builds"`
}
// BuildConfig contains the build-specific browser capabilities
BuildConfig struct {
Name string `json:"name"`
BrowserCapabilities []string `json:"browserCapabilities"`
}
// Routes map urls to fragments
Routes map[string]string
)
func ConfigFromFile(filename string) (*ProjectConfig, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
return ConfigFromReader(file)
}
func ConfigFromBytes(b []byte) (*ProjectConfig, error) {
r := bytes.NewReader(b)
return ConfigFromReader(r)
}
func ConfigFromReader(r io.Reader) (*ProjectConfig, error) {
var config ProjectConfig
dec := json.NewDecoder(r)
if err := dec.Decode(&config); err != nil {
return nil, err
}
return &config, nil
}