-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreference.go
46 lines (38 loc) · 1017 Bytes
/
reference.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
package main
import (
"archive/zip"
"encoding/json"
"golang.org/x/tools/godoc/vfs"
"golang.org/x/tools/godoc/vfs/zipfs"
)
// Reference stores information related to all programming language references
// available to the user.
type Reference struct {
Data []ReferenceData
FileSystem vfs.FileSystem
}
// ReferenceData stores information related to a single reference.
type ReferenceData struct {
Name string `json:"name"`
Title string `json:"title"`
Index string `json:"index"`
}
// OpenReference is used to import information about all references stored at
// the specified location.
func OpenReference(location string) (*Reference, error) {
rc, err := zip.OpenReader(location)
if err != nil {
return nil, err
}
fs := zipfs.New(rc, "reference_zipfs")
info, err := vfs.ReadFile(fs, "/info.json")
if err != nil {
return nil, err
}
var data []ReferenceData
err = json.Unmarshal(info, &data)
if err != nil {
return nil, err
}
return &Reference{Data: data, FileSystem: fs}, nil
}