-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswagger.go
More file actions
42 lines (34 loc) · 912 Bytes
/
Copy pathswagger.go
File metadata and controls
42 lines (34 loc) · 912 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
33
34
35
36
37
38
39
40
41
42
package main
import "net/http"
func RegisterSwaggerRoutes(mux *http.ServeMux) {
mux.Handle("/swagger-ui/",
http.StripPrefix("/swagger-ui/",
http.FileServer(http.Dir("./swagger-ui")),
),
)
mux.HandleFunc("GET /openapi.yaml", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "openapi.yaml")
})
mux.HandleFunc("GET /swagger", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(`<!doctype html>
<html>
<head>
<title>Company Registry API Swagger</title>
<link rel="stylesheet" href="/swagger-ui/swagger-ui.css">
</head>
<body>
<div id="swagger-ui"></div>
<script src="/swagger-ui/swagger-ui-bundle.js"></script>
<script>
window.onload = function() {
SwaggerUIBundle({
url: '/openapi.yaml',
dom_id: '#swagger-ui'
});
};
</script>
</body>
</html>`))
})
}