Skip to content

Commit aecbd36

Browse files
committed
chore: cleanup docs
1 parent 2d06b3d commit aecbd36

6 files changed

Lines changed: 1876 additions & 43 deletions

File tree

internal/api/docs.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package api
2+
3+
import (
4+
_ "embed"
5+
"net/http"
6+
)
7+
8+
//go:embed docs/openapi.yaml
9+
var openAPISpec []byte
10+
11+
//go:embed docs/index.html
12+
var docsHTML []byte
13+
14+
// Redoc 2.5.3 — https://cdn.jsdelivr.net/npm/redoc@2.5.3/bundles/redoc.standalone.js
15+
// Vendored so /docs doesn't depend on an external CDN and the script can't be
16+
// swapped out from under us. Bump by re-downloading from the same path with a
17+
// new version.
18+
//
19+
//go:embed docs/redoc.standalone.js
20+
var redocJS []byte
21+
22+
func (s *Server) openapi(w http.ResponseWriter, _ *http.Request) {
23+
w.Header().Set("Content-Type", "application/yaml")
24+
_, _ = w.Write(openAPISpec)
25+
}
26+
27+
func (s *Server) docs(w http.ResponseWriter, _ *http.Request) {
28+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
29+
_, _ = w.Write(docsHTML)
30+
}
31+
32+
func (s *Server) docsRedocJS(w http.ResponseWriter, _ *http.Request) {
33+
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
34+
w.Header().Set("Cache-Control", "public, max-age=86400")
35+
_, _ = w.Write(redocJS)
36+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta charset="utf-8" />
55
<title>Transcriber API</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
7-
<link rel="icon" href="data:," />
87
<style>
98
body {
109
margin: 0;
@@ -14,6 +13,6 @@
1413
</head>
1514
<body>
1615
<redoc spec-url="/openapi.yaml" hide-download-button></redoc>
17-
<script src="https://cdn.redocly.com/redoc/latest/bundles/redoc.standalone.js"></script>
16+
<script src="/docs/redoc.standalone.js"></script>
1817
</body>
1918
</html>

internal/api/docs/redoc.standalone.js

Lines changed: 1838 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/api/logo.svg

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/api/server.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api
22

33
import (
44
"crypto/rand"
5-
_ "embed"
65
"encoding/hex"
76
"encoding/json"
87
"net/http"
@@ -12,15 +11,6 @@ import (
1211
"transcriber/internal/transcriber"
1312
)
1413

15-
//go:embed openapi.yaml
16-
var openAPISpec []byte
17-
18-
//go:embed docs.html
19-
var docsHTML []byte
20-
21-
//go:embed logo.svg
22-
var logoSVG []byte
23-
2414
type Server struct {
2515
store *jobs.Store
2616
queue *jobs.Queue
@@ -46,7 +36,7 @@ func (s *Server) Routes(staticHandler http.Handler) http.Handler {
4636
mux.HandleFunc("GET /readyz", s.ready)
4737
mux.HandleFunc("GET /openapi.yaml", s.openapi)
4838
mux.HandleFunc("GET /docs", s.docs)
49-
mux.HandleFunc("GET /docs/logo.svg", s.docsLogo)
39+
mux.HandleFunc("GET /docs/redoc.standalone.js", s.docsRedocJS)
5040
if staticHandler != nil {
5141
mux.Handle("/", staticHandler)
5242
}
@@ -203,22 +193,6 @@ func (s *Server) health(w http.ResponseWriter, _ *http.Request) {
203193
_, _ = w.Write([]byte("ok"))
204194
}
205195

206-
func (s *Server) openapi(w http.ResponseWriter, _ *http.Request) {
207-
w.Header().Set("Content-Type", "application/yaml")
208-
_, _ = w.Write(openAPISpec)
209-
}
210-
211-
func (s *Server) docs(w http.ResponseWriter, _ *http.Request) {
212-
w.Header().Set("Content-Type", "text/html; charset=utf-8")
213-
_, _ = w.Write(docsHTML)
214-
}
215-
216-
func (s *Server) docsLogo(w http.ResponseWriter, _ *http.Request) {
217-
w.Header().Set("Content-Type", "image/svg+xml")
218-
w.Header().Set("Cache-Control", "public, max-age=86400")
219-
_, _ = w.Write(logoSVG)
220-
}
221-
222196
func (s *Server) ready(w http.ResponseWriter, _ *http.Request) {
223197
if _, ok := s.registry.Default(); !ok {
224198
writeError(w, http.StatusServiceUnavailable, "no default model")

0 commit comments

Comments
 (0)