This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
68 lines (57 loc) · 1.51 KB
/
routes.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package doc
import (
"fmt"
"net/http"
"os"
"path/filepath"
"github.com/calvinverse/service.provisioning/internal/config"
"github.com/calvinverse/service.provisioning/internal/router"
"github.com/go-chi/chi"
log "github.com/sirupsen/logrus"
)
// NewDocumentationRouter returns an APIRouter instance for the documentation routes.
func NewDocumentationRouter(config config.Configuration) router.APIRouter {
return &docRouter{
cfg: config,
}
}
type docRouter struct {
cfg config.Configuration
}
func (d *docRouter) Prefix() string {
return "doc"
}
// GetOpenApiJson godoc
// @Summary Returns the OpenAPI document for the current service
// @Description Returns the OpenAPI document for the current service
// @Tags doc
// @Accept json
// @Produce json
// @Success 200 {object} environment.Environment
// @Router /v1/doc [get]
func (d *docRouter) Routes(prefix string, r chi.Router) {
filesDir := ""
if d.cfg.IsSet("doc.path") {
filesDir = d.cfg.GetString("doc.path")
} else {
ex, err := os.Executable()
if err != nil {
log.Fatal(
fmt.Sprintf(
"Failed to locate the directory of the executable. Error was: %v",
err))
}
workDir := filepath.Dir(ex)
filesDir = filepath.Join(workDir, "doc")
}
log.Debug(
fmt.Sprintf(
"Using doc directory %s",
filesDir))
r.Get(prefix, func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filesDir+"/swagger.json")
})
}
func (d *docRouter) Version() int8 {
return 1
}