mirror of
https://github.com/kataras/iris.git
synced 2025-03-13 21:36:28 +01:00
example for automated apidoc tool named "yaag" 👍
Former-commit-id: 1afed4ac2913b5f135e44992cf060e44694ceacb
This commit is contained in:
parent
d7ec0d4416
commit
f68e547fb6
|
@ -258,6 +258,10 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) files to
|
|||
|
||||
https://github.com/kataras/iris/tree/master/middleware#third-party-handlers
|
||||
|
||||
### Automated API Documentation
|
||||
|
||||
- [yaag](apidoc/yaag/main.go)
|
||||
|
||||
### Testing
|
||||
|
||||
The `httptest` package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, [gavv](https://github.com/gavv).
|
||||
|
|
60
_examples/apidoc/yaag/main.go
Normal file
60
_examples/apidoc/yaag/main.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
|
||||
"github.com/betacraft/yaag/irisyaag"
|
||||
"github.com/betacraft/yaag/yaag"
|
||||
)
|
||||
|
||||
/*
|
||||
go get github.com/betacraft/yaag/...
|
||||
*/
|
||||
|
||||
type myXML struct {
|
||||
Result string `xml:"result"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware.
|
||||
On: true,
|
||||
DocTitle: "Iris",
|
||||
DocPath: "apidoc.html",
|
||||
BaseUrls: map[string]string{"Production": "", "Staging": ""},
|
||||
})
|
||||
app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware.
|
||||
|
||||
app.Get("/json", func(ctx context.Context) {
|
||||
ctx.JSON(context.Map{"result": "Hello World!"})
|
||||
})
|
||||
|
||||
app.Get("/plain", func(ctx context.Context) {
|
||||
ctx.Text("Hello World!")
|
||||
})
|
||||
|
||||
app.Get("/xml", func(ctx context.Context) {
|
||||
ctx.XML(myXML{Result: "Hello World!"})
|
||||
})
|
||||
|
||||
app.Get("/complex", func(ctx context.Context) {
|
||||
value := ctx.URLParam("key")
|
||||
ctx.JSON(context.Map{"value": value})
|
||||
})
|
||||
|
||||
// Run our HTTP Server.
|
||||
//
|
||||
// Documentation of "yaag" doesn't note the follow, but in Iris we are careful on what
|
||||
// we provide to you.
|
||||
//
|
||||
// Each incoming request results on re-generation and update of the "apidoc.html" file.
|
||||
// Recommentation:
|
||||
// Write tests that calls those handlers, save the generated "apidoc.html".
|
||||
// Turn off the yaag middleware when in production.
|
||||
//
|
||||
// Example usage:
|
||||
// Visit all paths and open the generated "apidoc.html" file to see the API's automated docs.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -115,7 +115,7 @@ type Controller struct {
|
|||
Data map[string]interface{}
|
||||
|
||||
ContentType string
|
||||
Text string // or Text
|
||||
Text string // response as string
|
||||
|
||||
// give access to the request context itself.
|
||||
Ctx context.Context
|
||||
|
|
Loading…
Reference in New Issue
Block a user