Middleware - Golang Web Dev

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 12

  • @transaphonic
    @transaphonic 3 ปีที่แล้ว

    Amazing 🔥🙏

    • @GrowAdept
      @GrowAdept  3 ปีที่แล้ว

      Thank you :)

  • @swibay
    @swibay 3 ปีที่แล้ว +2

    Very useful video again! I can see the bright future of your channel in the days of Go's bright future! Jesus bless you man!

    • @GrowAdept
      @GrowAdept  3 ปีที่แล้ว +1

      Thank you, will try to keep them coming :)

  • @jorisjansen2892
    @jorisjansen2892 2 ปีที่แล้ว +1

    Great explanation! What if we want to decode the JWT token in the middleware, and pass a few values to our handler?

    • @GrowAdept
      @GrowAdept  2 ปีที่แล้ว +2

      Good question, yes you can! This one deserves its own video. I have a couple of videos already lined up to create but I will put this on my list to make. Thank you for the input.

  • @ekekw930
    @ekekw930 2 ปีที่แล้ว

    Is there a way to easily make this session cookie store global? And also making the middleware global to use it for multiple routes over multiple controllers/handlers?

    • @GrowAdept
      @GrowAdept  2 ปีที่แล้ว +1

      The session cookie is stored on the user's machine in the browser they are running. This cookie will be sent with every request (this domain only), so any of our handlers could check to see if this cookie is valid. This is as long as the cookie has not expired yet. I hope I am answering your question in that it is "global" in the sense that all the handlers (in your domain only) can have access to it when a request comes into the server.
      The middleware can be used for multiple routes, inside of the http.HandleFunc(, ) you will need to use http.HandleFunc(, Auth()). You will just have to pass your handlers into the middleware you want to run, in this case it was our authentication middleware named Auth() . This is nice since you can easily add middleware to the routes you want. You can also create other middleware functions for things other than authentication should you be inclined.

    • @ekekw930
      @ekekw930 2 ปีที่แล้ว

      @@GrowAdept great explanation thank you!

    • @GrowAdept
      @GrowAdept  2 ปีที่แล้ว

      No problem

  • @subee128
    @subee128 2 ปีที่แล้ว

    Thanks