1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 21:15:56 +00:00

New feature: versioning.Aliases

Thanks @mulyawansentosa and @remopavithran for your donates ❤️
This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-01-06 01:52:39 +02:00
parent 7aa2d1f9d5
commit b409f7807e
28 changed files with 396 additions and 85 deletions

View File

@@ -64,14 +64,11 @@ func main() {
}
func handler(ctx iris.Context) {
// username, password, _ := ctx.Request().BasicAuth()
// third parameter it will be always true because the middleware
// makes sure for that, otherwise this handler will not be executed.
// OR:
user := ctx.User()
// OR ctx.User().GetRaw() to get the underline value.
username, _ := user.GetUsername()
password, _ := user.GetPassword()
// user := ctx.User().(*myUserType)
// or ctx.User().GetRaw().(*myUserType)
// ctx.Writef("%s %s:%s", ctx.Path(), user.Username, user.Password)
// OR if you don't have registered custom User structs:
username, password, _ := ctx.Request().BasicAuth()
ctx.Writef("%s %s:%s", ctx.Path(), username, password)
}

View File

@@ -152,7 +152,7 @@ func newApp() *iris.Application {
}
// wildcard subdomains.
wildcardSubdomain := app.Party("*.")
wildcardSubdomain := app.WildcardSubdomain()
{
wildcardSubdomain.Get("/", func(ctx iris.Context) {
ctx.Writef("Subdomain can be anything, now you're here from: %s", ctx.Subdomain())

View File

@@ -82,11 +82,11 @@ func registerGamesRoutes(app *iris.Application) {
}
func registerSubdomains(app *iris.Application) {
mysubdomain := app.Party("mysubdomain.")
mysubdomain := app.Subdomain("mysubdomain")
// http://mysubdomain.myhost.com
mysubdomain.Get("/", h)
willdcardSubdomain := app.Party("*.")
willdcardSubdomain := app.WildcardSubdomain()
willdcardSubdomain.Get("/", h)
willdcardSubdomain.Party("/party").Get("/", h)
}

View File

@@ -116,7 +116,7 @@ func main() {
adminRoutes.Get("/settings", info)
// Wildcard/dynamic subdomain
dynamicSubdomainRoutes := app.Party("*.")
dynamicSubdomainRoutes := app.WildcardSubdomain()
// GET: http://any_thing_here.localhost:8080
dynamicSubdomainRoutes.Get("/", info)

View File

@@ -33,7 +33,7 @@ func main() {
}*/
// no order, you can register subdomains at the end also.
dynamicSubdomains := app.Party("*.")
dynamicSubdomains := app.WildcardSubdomain()
{
dynamicSubdomains.Get("/", dynamicSubdomainHandler)

View File

@@ -45,10 +45,12 @@ func examplePerParty(app *iris.Application) {
// You can customize the way a version is extracting
// via middleware, for example:
// version url parameter, and, if it's missing we default it to "1".
usersAPI.Use(func(ctx iris.Context) {
versioning.SetVersion(ctx, ctx.URLParamDefault("version", "1"))
ctx.Next()
})
// usersAPI.Use(func(ctx iris.Context) {
// versioning.SetVersion(ctx, ctx.URLParamDefault("version", "1"))
// ctx.Next()
// })
// OR:
usersAPI.Use(versioning.FromQuery("version", "1"))
// version 1.
usersAPIV1 := versioning.NewGroup(usersAPI, ">= 1, < 2")

View File

@@ -114,7 +114,7 @@ func NewApp(sess *sessions.Sessions) *iris.Application {
app.Get("/delete", func(ctx iris.Context) {
session := sessions.Get(ctx)
// delete a specific key
session.Delete("name")
session.Delete("username")
})
app.Get("/clear", func(ctx iris.Context) {

View File

@@ -16,12 +16,12 @@ func TestSessionsEncodeDecode(t *testing.T) {
es.Cookies().NotEmpty()
es.Body().Equal("All ok session set to: iris [isNew=true]")
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The name on the /set was: iris")
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: iris")
// delete and re-get
e.GET("/delete").Expect().Status(iris.StatusOK)
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The name on the /set was: ")
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: ")
// set, clear and re-get
e.GET("/set").Expect().Body().Equal("All ok session set to: iris [isNew=false]")
e.GET("/clear").Expect().Status(iris.StatusOK)
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The name on the /set was: ")
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: ")
}

View File

@@ -37,6 +37,11 @@ func h(ctx iris.Context) {
// third parameter it will be always true because the middleware
// makes sure for that, otherwise this handler will not be executed.
// OR:
//
// user := ctx.User().(*myUserType)
// ctx.Writef("%s %s:%s", ctx.Path(), user.Username, user.Password)
// OR if you don't have registered custom User structs:
//
// ctx.User().GetUsername()
// ctx.User().GetPassword()
ctx.Writef("%s %s:%s", ctx.Path(), username, password)

View File

@@ -27,7 +27,7 @@ func main() {
// wildcard subdomain, will catch username1.... username2.... username3... username4.... username5...
// that our below links are providing via page.html's first argument which is the subdomain.
subdomain := app.Party("*.")
subdomain := app.WildcardSubdomain()
mypathRoute := subdomain.Get("/mypath", emptyHandler)
mypathRoute.Name = "my-page1"