forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
load.go
64 lines (56 loc) · 1.35 KB
/
load.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
54
55
56
57
58
59
60
61
62
63
64
package api
import (
"encoding/json"
"os"
"path/filepath"
)
// Load takes a set of files for each filetype and returns an API pointer.
// The API will be initialized once all files have been loaded and parsed.
//
// Will panic if any failure opening the definition JSON files, or there
// are unrecognized exported names.
func Load(api, docs, paginators, waiters string) *API {
a := API{}
a.Attach(api)
a.Attach(docs)
a.Attach(paginators)
a.Attach(waiters)
a.Setup()
return &a
}
// Attach opens a file by name, and unmarshal its JSON data.
// Will proceed to setup the API if not already done so.
func (a *API) Attach(filename string) {
a.path = filepath.Dir(filename)
f, err := os.Open(filename)
defer f.Close()
if err != nil {
panic(err)
}
json.NewDecoder(f).Decode(a)
}
// AttachString will unmarshal a raw JSON string, and setup the
// API if not already done so.
func (a *API) AttachString(str string) {
json.Unmarshal([]byte(str), a)
if !a.initialized {
a.Setup()
}
}
// Setup initializes the API.
func (a *API) Setup() {
a.writeShapeNames()
a.resolveReferences()
a.fixStutterNames()
a.renameExportable()
if !a.NoRenameToplevelShapes {
a.renameToplevelShapes()
}
a.updateTopLevelShapeReferences()
a.createInputOutputShapes()
a.customizationPasses()
if !a.NoRemoveUnusedShapes {
a.removeUnusedShapes()
}
a.initialized = true
}