Comments (1)
The *web.Service
instance also exposes chi.Router
and so you can mount static content directly into it.
Please check the following example:
package main
import (
"context"
"net/http"
"github.com/swaggest/rest/web"
"github.com/swaggest/swgui/v4emb"
"github.com/swaggest/usecase"
)
func getItemByID() usecase.Interactor {
type inp struct {
ID int `path:"id"`
}
return usecase.NewInteractor[inp, string](func(ctx context.Context, i inp, o *string) error {
*o = "abc!"
return nil
})
}
func main() {
// setup REST interface with OpenAPI documentation
s := web.DefaultService()
s.OpenAPI.Info.Title = "..."
s.OpenAPI.Info.WithDescription("...")
s.OpenAPI.Info.Version = "v0.0.1"
s.Get("/api/v1/item/{id}", getItemByID())
// etc...
s.Docs("/api/v1/docs", v4emb.New) // relocate swaggest to /api/v1/...
// static html/css/js files served from embedded FS
//uiFS := webui.StaticFS()
s.Mount("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(r.URL.String()))
})) // provide static files at /
http.ListenAndServe("localhost:8080", s)
}
There is also support for Mount
introspection (added recently in rest
v0.2.30
), please check the example: https://github.com/swaggest/rest/blob/v0.2.30/_examples/mount/main.go.
There is also a small discussion about Mount
in swaggest/rest#84.
from swgui.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swgui.