-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.go
More file actions
32 lines (27 loc) · 872 Bytes
/
constructor.go
File metadata and controls
32 lines (27 loc) · 872 Bytes
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
package getdoc
import (
"fmt"
"io"
"github.com/PuerkitoBio/goquery"
)
// Constructor represents constructor documentation.
type Constructor struct {
Name string `json:"name"`
Description []string `json:"description,omitempty"`
Links []string `json:"links,omitempty"`
Fields map[string]ParamDescription `json:"fields,omitempty"`
}
// ParseConstructor parses html documentation from reader and produces Constructor.
func ParseConstructor(reader io.Reader) (*Constructor, error) {
doc, err := goquery.NewDocumentFromReader(reader)
if err != nil {
return nil, fmt.Errorf("failed to parse document: %w", err)
}
desc, links := docDescription(doc)
return &Constructor{
Name: docTitle(doc),
Description: desc,
Links: links,
Fields: docParams(doc),
}, nil
}