feat: use go embed for swagger (#15216)

This commit is contained in:
Julien Robert
2023-02-28 15:21:38 +00:00
committed by GitHub
parent 1273c05ada
commit d2977478bc
18 changed files with 14 additions and 58 deletions
+6 -7
View File
@@ -1,14 +1,13 @@
package server
import (
"fmt"
"io/fs"
"net/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik" // we use this to help with sderving the docs
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/docs"
)
// RegisterSwaggerAPI provides a common function which registers swagger route with API Server
@@ -17,12 +16,12 @@ func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router, swaggerEnabled bool)
return nil
}
statikFS, err := fs.New()
root, err := fs.Sub(docs.SwaggerUI, "swagger-ui")
if err != nil {
return fmt.Errorf("failed to create filesystem: %w", err)
return err
}
staticServer := http.FileServer(statikFS)
staticServer := http.FileServer(http.FS(root))
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
return nil