Understanding Contexts in Go in 5(-ish?) Minutes

Поділитися
Вставка
  • Опубліковано 22 сер 2024
  • 👨‍💻 For the price of $7.99 every month, sign up and gain access to a growing list of premium courses on my site - tutorialedge.n...
    Welcome Gophers, in this video, we'll be covering the topic of contexts within Go and how you an use them to propagate key/values through your application and also to handle things like timeouts. If you prefer, the original text version of this article can be found here - tutorialedge.n...
    ✅ Subscribe and hit that 🔔 to get notified for all the latest tutorials!
    🤓 / elliot_f
    ‎💻 tutorialedge.net
    🎥 Recording Setup
    Microphone - amzn.to/3hvASys
    Mic Boom - amzn.to/3o0cW8Q
    Mouse - amzn.to/2WZMoZs
    Monitor 1 - amzn.to/38IUlYy
    Monitor 2 - amzn.to/3rBTZf7
    Mount - amzn.to/3o3185V
    USB-C Hub - amzn.to/3o2xRbw

КОМЕНТАРІ • 40

  • @eduardozepeda1972
    @eduardozepeda1972 2 роки тому +13

    I searched for tutorials about go's context and yours was the only one I understood. Thank you so much.

  • @liang306
    @liang306 Місяць тому

    Nicely explained. I like how the video started with "what and why", and give a brief overview of the concept!

  • @KoltPenny
    @KoltPenny Рік тому +2

    I want my $0.00001 from the ads back 😆. Great video, keep it up.

  • @fuadadio
    @fuadadio 4 місяці тому +1

    Finally understood this concept. Thank you so much.

  • @TomDoesTech
    @TomDoesTech 2 роки тому +12

    So early it's still in 360p :) Great video!

  • @kumar-jatin-2000
    @kumar-jatin-2000 6 місяців тому +1

    Really well made video. Thank you.

  • @cariyaputta
    @cariyaputta 2 роки тому +9

    Would you please cover the case of context use with grpc? Like how does the grpc lib make use of context, or how to use it for auth ...

  • @Nuraddinhassan
    @Nuraddinhassan 7 місяців тому

    your are my friend make my love golang, you are really great teacher, 😇🙂

  • @adedoyinphilip8647
    @adedoyinphilip8647 2 роки тому +1

    Thank you for this. Quite explanatory! 🙏

  • @michaeldausmann6066
    @michaeldausmann6066 2 роки тому +1

    good explanation. thanks.

  • @giridharanpasupathi
    @giridharanpasupathi Рік тому

    Good explanation bro... ✔️

  • @HasanAYousef
    @HasanAYousef 2 роки тому +3

    Great and simple, a side question, what is the theme you are using at VS code?

  • @m_205
    @m_205 Рік тому

    It's very helpful. Thank you so much for the effort.

  • @feynmaz
    @feynmaz 2 роки тому

    Thank You. The tutorial is great!

  • @keivinc
    @keivinc Рік тому

    thank you for the very good explanation 😀

  • @zawkhaled
    @zawkhaled 2 роки тому

    Definitely removed some of the confusion!

  • @garryhall9652
    @garryhall9652 2 роки тому +3

    something that caused a little bit of confusion to me: the `

  • @kevinkkirimii
    @kevinkkirimii 6 місяців тому

    A question 10:40 is there need for the select case at line 35 since ctx.done() blocks and will be invoked once the timeout has exceeded ?!

  • @gonzariosm
    @gonzariosm 2 роки тому

    Great example, thanks a lot for the info :D

  • @DiegoGago
    @DiegoGago 2 роки тому +2

    I've always wondered if sending information or adding logic via context is not a kind of hidden dependency in my code. Some people consider it a bad practice.

    • @klarnorbert
      @klarnorbert 2 роки тому

      It is, and it shouldn't be used at all, according to Google.

    • @amitabhojha6117
      @amitabhojha6117 2 роки тому +5

      ​@@klarnorbert A citation would be great.

  • @PeterNunnOZ
    @PeterNunnOZ 2 роки тому

    Good explination.

    • @Tutorialedge
      @Tutorialedge  2 роки тому

      Thank you Peter! I hope you are keeping well!

  • @nsevalkar
    @nsevalkar Рік тому

    Can you share your emacs config?

  • @TechEats
    @TechEats 2 роки тому +1

    This audio is not clear. would be great if you can add subtitles

  • @pb8655
    @pb8655 Рік тому

    Wouldn’t it make sense to pass context by pointer?

    • @pb8655
      @pb8655 Рік тому

      If go is copying by value, shouldn’t ctx.done lose reference to the outer scope

  • @mwnkt
    @mwnkt Рік тому

    i kinda understand context. though still not so clear.

  • @davidjdriver
    @davidjdriver 7 місяців тому

    This is one part of go I really don't get. It hides dependencies inside a super parameter. If your method needs to know something it should be explicit or in scope of the struct as a base config. Putting values into a dictionary and passing the dictionary around hides the dependency. I don't understand how this became used in Go at all as it is actually an anti-pattern.

    • @Tutorialedge
      @Tutorialedge  7 місяців тому

      I think there's a bit of a misunderstanding about the intent of context.Context here. You absolutely should not use it for things that are needed by the function, but the context may be used to pass extraneous information such as the request_id or trace_id that's currently being handled so that you can enrich logs/traces without polluting your function's logic and making it overly complex.
      If there are hard dependencies needed by your functions or methods, then these should be either passed in, or set on the struct that the method hangs off of.

    • @NateSelzer
      @NateSelzer 20 днів тому

      ​@@Tutorialedge I'm not sure how timeouts/deadlines fit into the "not needed by the function" category. Seems like critical functionality that functions should need to handle. For example, if you time out in the middle of a function that updates 2 different data sources with related information (let's say, a database entry that points to a file storage URL), the function would need to react to a timeout or this would result in data inconsistency.

  • @user-zj8dp8ue1z
    @user-zj8dp8ue1z 2 роки тому

    広めてください」、

  • @sorrowseal
    @sorrowseal 2 роки тому

    Video is only 360p, too blurry.

    • @sorrowseal
      @sorrowseal 2 роки тому

      All good now, youtube took longer than it used to.

  • @elgs1980
    @elgs1980 2 роки тому +2

    I don't think this should be part of the Go language.

    • @joshuatye1027
      @joshuatye1027 Місяць тому

      This is basically the go community on everything.

  • @susiebaka3388
    @susiebaka3388 Рік тому

    it took you 8 minutes to get to the context interface despite this being a tutorial on contexts in Go ...