move server/* to scnserver/*
This commit is contained in:
35
scnserver/swagger/index.html
Normal file
35
scnserver/swagger/index.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>API Documentation</title>
|
||||
<link rel="stylesheet" href="swagger-ui.css" />
|
||||
<!-- <link rel="stylesheet" href="themes/theme-feeling-blue.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-flattop.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-material.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-monokai.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-muted.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-newspaper.css" /> -->
|
||||
<!-- <link rel="stylesheet" href="themes/theme-outline.css" /> -->
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="swagger-ui-bundle.js" crossorigin></script>
|
||||
<script src="swagger-ui-standalone-preset.js" crossorigin></script>
|
||||
<script>
|
||||
window.onload = () => {
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: './swagger.json',
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
defaultModelsExpandDepth: 0,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
3
scnserver/swagger/swagger-ui-bundle.js
Normal file
3
scnserver/swagger/swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
scnserver/swagger/swagger-ui-standalone-preset.js
Normal file
3
scnserver/swagger/swagger-ui-standalone-preset.js
Normal file
File diff suppressed because one or more lines are too long
4
scnserver/swagger/swagger-ui.css
Normal file
4
scnserver/swagger/swagger-ui.css
Normal file
File diff suppressed because one or more lines are too long
70
scnserver/swagger/swagger.go
Normal file
70
scnserver/swagger/swagger.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||
"embed"
|
||||
_ "embed"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
//go:embed *.json
|
||||
//go:embed *.yaml
|
||||
//go:embed *.js
|
||||
//go:embed *.css
|
||||
//go:embed themes/*
|
||||
var assets embed.FS
|
||||
|
||||
func getAsset(fn string) ([]byte, string, bool) {
|
||||
data, err := assets.ReadFile(fn)
|
||||
if err != nil {
|
||||
return nil, "", false
|
||||
}
|
||||
|
||||
mime := "text/plain"
|
||||
|
||||
lowerFN := strings.ToLower(fn)
|
||||
if strings.HasSuffix(lowerFN, ".html") || strings.HasSuffix(lowerFN, ".htm") {
|
||||
mime = "text/html"
|
||||
} else if strings.HasSuffix(lowerFN, ".css") {
|
||||
mime = "text/css"
|
||||
} else if strings.HasSuffix(lowerFN, ".js") {
|
||||
mime = "text/javascript"
|
||||
} else if strings.HasSuffix(lowerFN, ".json") {
|
||||
mime = "application/json"
|
||||
} else if strings.HasSuffix(lowerFN, ".jpeg") || strings.HasSuffix(lowerFN, ".jpg") {
|
||||
mime = "image/jpeg"
|
||||
} else if strings.HasSuffix(lowerFN, ".png") {
|
||||
mime = "image/png"
|
||||
} else if strings.HasSuffix(lowerFN, ".svg") {
|
||||
mime = "image/svg+xml"
|
||||
}
|
||||
|
||||
return data, mime, true
|
||||
}
|
||||
|
||||
func Handle(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
Filename string `uri:"sub"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
if err := g.ShouldBindUri(&u); err != nil {
|
||||
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
}
|
||||
|
||||
u.Filename = strings.TrimLeft(u.Filename, "/")
|
||||
|
||||
if u.Filename == "" {
|
||||
index, _, _ := getAsset("index.html")
|
||||
return ginresp.Data(http.StatusOK, "text/html", index)
|
||||
}
|
||||
|
||||
if data, mime, ok := getAsset(u.Filename); ok {
|
||||
return ginresp.Data(http.StatusOK, mime, data)
|
||||
}
|
||||
|
||||
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": u.Filename})
|
||||
}
|
3075
scnserver/swagger/swagger.json
Normal file
3075
scnserver/swagger/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
2064
scnserver/swagger/swagger.yaml
Normal file
2064
scnserver/swagger/swagger.yaml
Normal file
File diff suppressed because it is too large
Load Diff
1672
scnserver/swagger/themes/theme-feeling-blue.css
Normal file
1672
scnserver/swagger/themes/theme-feeling-blue.css
Normal file
File diff suppressed because it is too large
Load Diff
1672
scnserver/swagger/themes/theme-flattop.css
Normal file
1672
scnserver/swagger/themes/theme-flattop.css
Normal file
File diff suppressed because it is too large
Load Diff
1719
scnserver/swagger/themes/theme-material.css
Normal file
1719
scnserver/swagger/themes/theme-material.css
Normal file
File diff suppressed because it is too large
Load Diff
1792
scnserver/swagger/themes/theme-monokai.css
Normal file
1792
scnserver/swagger/themes/theme-monokai.css
Normal file
File diff suppressed because it is too large
Load Diff
1673
scnserver/swagger/themes/theme-muted.css
Normal file
1673
scnserver/swagger/themes/theme-muted.css
Normal file
File diff suppressed because it is too large
Load Diff
1671
scnserver/swagger/themes/theme-newspaper.css
Normal file
1671
scnserver/swagger/themes/theme-newspaper.css
Normal file
File diff suppressed because it is too large
Load Diff
1652
scnserver/swagger/themes/theme-outline.css
Normal file
1652
scnserver/swagger/themes/theme-outline.css
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user