feat: use go embed for swagger (#15216)
This commit is contained in:
+6
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user