mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 23:40:35 +01:00
Modification
- Add configurator for Party - Modification for CORS middleware example Former-commit-id: f01c01d4eac41666a92890461851909a6ade018b
This commit is contained in:
parent
72b096e156
commit
643358d7cb
|
@ -13,14 +13,14 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
crs := cors.New(cors.Options{
|
crs := cors.NewPartyMiddleware(cors.Options{
|
||||||
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
|
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
|
||||||
AllowedMethods: router.AllMethods[:],
|
AllowedMethods: router.AllMethods[:],
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
v1 := app.Party("/api/v1")
|
v1 := app.Party("/api/v1")
|
||||||
v1.Use(crs)
|
v1.ConfigureParty(crs)
|
||||||
{
|
{
|
||||||
v1.Get("/home", func(ctx iris.Context) {
|
v1.Get("/home", func(ctx iris.Context) {
|
||||||
ctx.WriteString("Hello from /home")
|
ctx.WriteString("Hello from /home")
|
||||||
|
|
|
@ -114,6 +114,14 @@ func NewAPIBuilder() *APIBuilder {
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigureParty configures this party like `iris.Application#Configure`
|
||||||
|
// That allows middlewares focused on the Party like CORS middleware
|
||||||
|
func (api *APIBuilder) ConfigureParty(conf ...PartyConfigurator) {
|
||||||
|
for _, h := range conf {
|
||||||
|
h(api)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetRelPath returns the current party's relative path.
|
// GetRelPath returns the current party's relative path.
|
||||||
// i.e:
|
// i.e:
|
||||||
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
||||||
|
|
|
@ -9,11 +9,18 @@ import (
|
||||||
// Party is here to separate the concept of
|
// Party is here to separate the concept of
|
||||||
// api builder and the sub api builder.
|
// api builder and the sub api builder.
|
||||||
|
|
||||||
|
// PartyConfigurator is handler for configuring a party (it works with iris.Application)
|
||||||
|
type PartyConfigurator func(party Party)
|
||||||
|
|
||||||
// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
|
// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
|
||||||
// Party could also be named as 'Join' or 'Node' or 'Group' , Party chosen because it is fun.
|
// Party could also be named as 'Join' or 'Node' or 'Group' , Party chosen because it is fun.
|
||||||
//
|
//
|
||||||
// Look the "APIBuilder" for its implementation.
|
// Look the "APIBuilder" for its implementation.
|
||||||
type Party interface {
|
type Party interface {
|
||||||
|
// ConfigureParty configures this party like `iris.Application#Configure`
|
||||||
|
// That allows middlewares focused on the Party like CORS middleware
|
||||||
|
ConfigureParty(...PartyConfigurator)
|
||||||
|
|
||||||
// GetRelPath returns the current party's relative path.
|
// GetRelPath returns the current party's relative path.
|
||||||
// i.e:
|
// i.e:
|
||||||
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
// if r := app.Party("/users"), then the `r.GetRelPath()` is the "/users".
|
||||||
|
|
Loading…
Reference in New Issue
Block a user