Code Monkey home page Code Monkey logo

Comments (5)

kataras avatar kataras commented on May 30, 2024 1

@corebreaker thanks for your interest but it was an easy and quick fix, no need to wait more time for that. Could you please upgrade and confirm if that was the behavior you wanted to or not?

from iris.

hiveminded avatar hiveminded commented on May 30, 2024

Hello, you use the wrong function: when we don't care about order and/or a middleware needed to be registered to all routes (incl parties and subdomains) then we have to use the UseGlobal instead of Use function. Give it a try and inform us, thank you.

from iris.

corebreaker avatar corebreaker commented on May 30, 2024

Ah, ok it works, UseGlobal is the right function, thank you.

I knew it, but i thought that it have the same behavior, but i should test it before posting that issue.

from iris.

corebreaker avatar corebreaker commented on May 30, 2024

It's true that with UseGlobal the "/path1.txt" route call the middleware but cause the prepend, the order is inversed:

package main

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/context"
)

func main() {
	app := iris.New()

	app.UseGlobal(func(ctx context.Context) {
		ctx.Text("MIDDLEWARE 1\n")
		ctx.Next()
	})

	app.UseGlobal(func(ctx context.Context) {
		ctx.Text("MIDDLEWARE 2\n")
		ctx.Next()
	})

	app.Get("/path.txt", func(ctx context.Context) {
		ctx.Text("PATH")
	})

	app.Run(iris.Addr(":8080"))
}

With curl http://localhost:8080/path2.txt ; echo, we have:

MIDDLEWARE2
MIDDLEWARE1
PATH

We can conserve the order, i'll post a PR, you'll see if you want merge it.

from iris.

corebreaker avatar corebreaker commented on May 30, 2024

Great! It works!
Now designing a server is really powerful. I like Django and Iris is now the best alternative in Go.

from iris.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.