-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocs.go
More file actions
64 lines (57 loc) · 1.85 KB
/
docs.go
File metadata and controls
64 lines (57 loc) · 1.85 KB
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 shiftapi
import (
"html/template"
"io"
)
const docsTemplate string = `<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/scalar-api-reference/1.36.2/standalone.min.js" integrity="sha512-1eGM3+sAmNpB7cn/i3KOVszLEAph0LC96/Qk1T0hf/eK8p0MSU7og2mx0P0bv5R4R8U7LWJnA9cDCxp7RRdF/Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
Scalar.createApiReference('#app', {
url: '{{.SpecURL}}',
})
</script>
</body>
</html>
`
const asyncDocsTemplate string = `<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/@asyncapi/react-component@3.0.2/styles/default.min.css" integrity="sha384-+kAXZlmkYbACsvDm+h2/qAphvw98RHOGObISB6ouInRvC2tvmBLwvgZVZQOtMndl" crossorigin="anonymous">
</head>
<body>
<div id="asyncapi"></div>
<script src="https://unpkg.com/@asyncapi/react-component@3.0.2/browser/standalone/index.js" integrity="sha384-qYnchRkiLeA3INQMui0zmEqOZzAdSM6DTME5EPknhPDJNfi5FkyRVoSKfswOT1K/" crossorigin="anonymous"></script>
<script>
AsyncApiStandalone.render({
schema: { url: '{{.SpecURL}}' },
config: { show: { sidebar: true } },
}, document.getElementById('asyncapi'));
</script>
</body>
</html>
`
var (
docsTmpl = template.Must(template.New("docsHTML").Parse(docsTemplate))
asyncDocsTmpl = template.Must(template.New("asyncDocsHTML").Parse(asyncDocsTemplate))
)
type docsData struct {
Title string
SpecURL string
}
func genDocsHTML(data docsData, out io.Writer) error {
return docsTmpl.Execute(out, data)
}
func genAsyncDocsHTML(data docsData, out io.Writer) error {
return asyncDocsTmpl.Execute(out, data)
}