Cleaner swagger routes
This commit is contained in:
parent
8582674b44
commit
2b4d77bab4
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
|
||||||
<data-source source="LOCAL" name="DataSource" uuid="4345c0f7-e4f6-49f3-8694-3827ae63cc61">
|
|
||||||
<driver-ref>sqlite.xerial</driver-ref>
|
|
||||||
<synchronize>true</synchronize>
|
|
||||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
|
||||||
<jdbc-url>jdbc:sqlite:identifier.sqlite</jdbc-url>
|
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
|
||||||
</data-source>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -61,9 +61,7 @@ func (r *Router) Init(e *gin.Engine) {
|
|||||||
docs := e.Group("/documentation")
|
docs := e.Group("/documentation")
|
||||||
{
|
{
|
||||||
docs.GET("/swagger", ginext.RedirectTemporary("/documentation/swagger/"))
|
docs.GET("/swagger", ginext.RedirectTemporary("/documentation/swagger/"))
|
||||||
docs.GET("/swagger/", ginresp.Wrap(swagger.Handle))
|
docs.GET("/swagger/*sub", ginresp.Wrap(swagger.Handle))
|
||||||
docs.GET("/swagger/:fn1", ginresp.Wrap(swagger.Handle))
|
|
||||||
docs.GET("/swagger/:fn1/:fn2", ginresp.Wrap(swagger.Handle))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Website ================
|
// ================ Website ================
|
||||||
|
@ -13,9 +13,9 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var conf = scn.Conf
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
conf := scn.Conf
|
||||||
|
|
||||||
scn.Init(conf)
|
scn.Init(conf)
|
||||||
|
|
||||||
log.Info().Msg(fmt.Sprintf("Starting with config-namespace <%s>", conf.Namespace))
|
log.Info().Msg(fmt.Sprintf("Starting with config-namespace <%s>", conf.Namespace))
|
||||||
|
@ -47,8 +47,7 @@ func getAsset(fn string) ([]byte, string, bool) {
|
|||||||
|
|
||||||
func Handle(g *gin.Context) ginresp.HTTPResponse {
|
func Handle(g *gin.Context) ginresp.HTTPResponse {
|
||||||
type uri struct {
|
type uri struct {
|
||||||
Filename1 string `uri:"fn1"`
|
Filename string `uri:"sub"`
|
||||||
Filename2 *string `uri:"fn2"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var u uri
|
var u uri
|
||||||
@ -56,19 +55,16 @@ func Handle(g *gin.Context) ginresp.HTTPResponse {
|
|||||||
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := u.Filename1
|
u.Filename = strings.TrimLeft(u.Filename, "/")
|
||||||
if u.Filename2 != nil {
|
|
||||||
filename = filename + "/" + *u.Filename2
|
|
||||||
}
|
|
||||||
|
|
||||||
if filename == "" {
|
if u.Filename == "" {
|
||||||
index, _, _ := getAsset("index.html")
|
index, _, _ := getAsset("index.html")
|
||||||
return ginresp.Data(http.StatusOK, "text/html", index)
|
return ginresp.Data(http.StatusOK, "text/html", index)
|
||||||
}
|
}
|
||||||
|
|
||||||
if data, mime, ok := getAsset(filename); ok {
|
if data, mime, ok := getAsset(u.Filename); ok {
|
||||||
return ginresp.Data(http.StatusOK, mime, data)
|
return ginresp.Data(http.StatusOK, mime, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": filename, "filename1": u.Filename1, "filename2": u.Filename2})
|
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": u.Filename})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user