justforfunc #9: The Context Package

Поделиться
HTML-код
  • Опубликовано: 23 дек 2024

Комментарии • 160

  • @rfgraham85
    @rfgraham85 7 лет назад +132

    5 minutes into the video and you've made more sense than the last 10 videos I've watched around Go concepts. Incredible approach to teaching while covering real world scenarios. Amazong job. Subbed!

    • @edwingarcia5043
      @edwingarcia5043 3 года назад

      What makes you think that the other videos didn't help you to get ready for watching this one video? 🤔

    • @johnryan6020
      @johnryan6020 2 года назад

      @@edwingarcia5043 That happens too, doesn't it. Great point (if not misplaced)!
      Most likely, it doesn't materially negate the effectiveness of Francesc's approach. It's a vector field and Rob seemed to clearly be using a short-hand to say, "damn, this vector has a magnitude and direction that helped me."

  • @ozerbdy
    @ozerbdy 6 лет назад +15

    Very clear explanation, with mental leaps just at the right times. And also blending the real world use cases into the examples is very well thought of. Thank you!

    • @JustForFunc
      @JustForFunc  6 лет назад

      Wow, that's such a nice thing to say!
      Thanks 😊

  • @ogreeni
    @ogreeni Год назад +12

    I’ve been learning go for less than a week, and just encountered your channel. Sad to see you no longer upload, these videos are really good.

  • @RamiAwar
    @RamiAwar 2 года назад

    I love the preaching of good practices like not using the context to pass values unless absolutely necessary. This aligns with how I like to write code, even though I've seen other developers use context to pass non-request scoped data. This channel seems to be a hidden gem!

    • @RamiAwar
      @RamiAwar 2 года назад

      Kind of got scared by the video length at first though, glad I watched it anyways.

  • @Filhodanuvem
    @Filhodanuvem 3 года назад

    From time to time I come back here and watch a random video. It inspires me so much. Thank you.

  • @YBWang-pi9qq
    @YBWang-pi9qq 3 года назад +2

    Amazing explanations with examples. One of the most talent instructors.
    Thanks you and keep doing it.

  • @davudsafarli5356
    @davudsafarli5356 4 года назад +3

    Thank you! I don't understand why no one starts by giving simple example like you do

  • @willhawkins7391
    @willhawkins7391 6 лет назад +1

    Francesc, I know this is an old Just for Func but I went back and watched it today and wanted to say Thanks! Great episode. As others have said, the explanation is perfect! Just what I needed. Thanks again and keep up the great work!

  • @yeboahnanaosei
    @yeboahnanaosei 4 года назад +1

    This video is my go to reference material on go's contexts. Thank you very much

  • @markmcdonnell
    @markmcdonnell 7 лет назад +10

    thanks Frances, the quality of this video and its contents is exceptional :-)

  • @juliankandlhofer7553
    @juliankandlhofer7553 4 года назад +1

    Great video! I watched 2 talkes before and was more confused about contexts after watching them.
    this video explained everything!

  • @alfaex.
    @alfaex. 7 лет назад

    i read a lot of posts on medium and the GO blog about context and i was completely lost... with this video it was very easy to understand. Amazing job

  • @newshatavakoli5960
    @newshatavakoli5960 4 года назад

    Thanks for the great video. This video was just the right speed and amount of explanation that I needed, very to the point. Watching you code through the examples, I learned things other than the context package too.

  • @daveteare1960
    @daveteare1960 7 лет назад +4

    I really enjoyed this episode - thank you! I've seen context used a lot and never really understood it until now. ❤️

  • @mohsanabbas6835
    @mohsanabbas6835 3 года назад +1

    Best video on the topic. Thanks

  • @DineshGowda24
    @DineshGowda24 4 года назад

    Thank you for this, this is amazing. I have read about context package, but couldn't really understand. But this 36 mins have been priceless. Very well done.

  • @derdere7803
    @derdere7803 Год назад

    I keep coming back to this video over time. It has a lot of value. Thanks for taking time and doing that. Where are you by the way, get back here and produce some more please.

  • @UnknownStuff0417
    @UnknownStuff0417 4 года назад +1

    Great video. A very important concept for setting up and handling things like timeouts and even exceptions in Go. I don't see this being addressed in other Go overview sites/videos. Really happy to come accross this.
    However, perhaps its just me but I don't think the last point/topic on sending value between "client.go" and "server.go" had appropriate phrasing from @justforfunc. I get his explanation for "foo" id to properly show up, the client has to include it as a header/body/uri-id as they are purely HTTP request data/communication. But that has nothing to do with inherently Go or even "context". I sort of interpreted this context as some internal "Go" communication between the client.go and server.go processes. And really the context in both client.go and server.go are between the those process' and operating system, but something like an HTTP client and server are really good examples to show where "context" is very applicable.
    Really good video but slightly misleading.

  • @vbcv1
    @vbcv1 5 лет назад +6

    I wonder how many developers would recognise "modern bear" t-shirt. Thanks for fueling up my desire to learn Go! Woof 😋

  • @raam_sevak
    @raam_sevak 6 лет назад

    I kept trying sending value with a context over the http to another machine, I stopped after I watched this video. Very detailed! I love your videos :D

  • @notangryjustdismayed
    @notangryjustdismayed 7 лет назад

    very timely upload. was just playing around with this today and i wasn't quite sure if i was using it properly. thank you!

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      I hope it will help you! Feel free to ask any questions at the end :-)

    • @notangryjustdismayed
      @notangryjustdismayed 7 лет назад

      thanks, this was a great video! one question i still have is this: i see a lot of talk about not storing contexts anywhere, and only passing contexts around as parameters. i don't have a problem with this, but i wonder why this is so important? what would be some of the unintended consequences of a struct holding a reference to a context? does the same rule apply to cancellation functions? (ok that was more than one question. i'm sorry)
      cheers!

    • @pm71241
      @pm71241 7 лет назад

      I was a little puzzled by your suggestion to not use Context values to store information which affects program flow.
      I mean... I understand the argument, but I fail to see the alternative for HTTP middleware.
      First, sure, it's a given that it should only be used for request-scoped values and request-id is a prime example.
      But you recommended to pass request scoped values which affected program flow as parameters. That is of course in general correct for any code, but for HTTP middleware you are kinda stuck with the http.Handler interface (reponsewriter, request).
      So how would you pass, say, "user id" to a handler you wrap around without creating your own alternative to http.Handler and making your code less composable?

  • @EnginDumlu
    @EnginDumlu 7 лет назад +9

    Thanks Frances, was a clear explanation.
    Can you please do the next episode about package initialization, sharing variables (like db / session) around between packages?

  • @chimmychingo6703
    @chimmychingo6703 2 года назад

    Loved this video. Watched a few that didnt quite get through, but this really brought into the right “context” xD

  • @tomah911
    @tomah911 6 лет назад

    I'm so glad I found your RUclips channel ! This video is perfect to understand how to use the Context package, thx !

  • @vishalsh1624
    @vishalsh1624 3 года назад

    Amazing explanation with real world examples. Thank you so much!

  • @mattmarshall1834
    @mattmarshall1834 3 года назад

    Great video. I'd been reading about context this afternoon and this very much tied up some mental loose ends I still had.

  • @MiguelAngelLastYear
    @MiguelAngelLastYear 7 лет назад +16

    Priceless, as always.
    What about an episode about how to create applications that work at the same time on multiple servers, as a cluster? The guides I have seen are ambiguous and do not share the good practices they proclaim.
    That, or an episode about when it is recommendable to create gorutines and when not.
    Thank you, Francesc!

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      +Miguel Ángel Jimeno Arce can you give an example? Do you mean something like a cluster database?

    • @MiguelAngelLastYear
      @MiguelAngelLastYear 7 лет назад +5

      JustForFunc yeah, a cluster database, a load balancer, a proxy to redirect http traffic, or a massive scanner which distributes traffic between available servers (my original idea was something pretty similar to this) and when it finalizes, joins results.
      Thank you!

  • @Alfrednohike9909
    @Alfrednohike9909 Год назад

    Hi, I would love to hear from you, as someone with a lot of experience in Golang, do you think SOLID Principles important in practice, and in interviews? Would I be asked a lot of questions, and how would I go about that, considering that SOLID Principles are mostly OOP concepts, and Golang is not a real OOP language. I am also curious about the same for design patterns like Builder, Factory pattern etc

  • @lhpegz
    @lhpegz Год назад

    lets say about following the trace-id and span-id, both are probably good values for contexts right?

  • @kianyanglee4618
    @kianyanglee4618 8 месяцев назад

    What's the != symbol at @15:46? Shouldn't it be !=?

  • @Jordan-kk5xj
    @Jordan-kk5xj 2 года назад

    Regarding the ability for the HTTP client to "cancel" the request via the context which notifies the HTTP server, I assume this would only work with such a golang client and a golang server, correct? I.e. this is impossible with say a Java client and golang server, correct?

  • @xcvsdxvsx
    @xcvsdxvsx 4 года назад

    Thanks so much! 7 minutes in and I now understand what the code does that I was trying to decipher.

  • @aguiwang7876
    @aguiwang7876 2 года назад

    I am big fan from China who watch your video every day before sleep! 😀

  • @Ysonichero
    @Ysonichero 4 года назад

    Thank you Frances, it’s really help me to understand context package.

  • @kamal-xd7id
    @kamal-xd7id 7 лет назад +1

    Do you have any other example for context with value other than request id? It would be better to understand this concept if you can. Thanks!

  • @ZenMonkIlya
    @ZenMonkIlya 3 года назад

    Excellent explanation. This is very helpful. Thank you!

  • @sergeywhite8897
    @sergeywhite8897 4 года назад +2

    Thank you, you're REALLY doing well. Thank you one more time!!!

  • @OfferoC
    @OfferoC 7 лет назад +1

    Nice vscode setup. Can you describe the exact set up somewhere in a post or video?

  • @alesresta
    @alesresta 7 лет назад

    I've been learning so much watching your videos! Thank you very much.

  • @dmytro.tsapko
    @dmytro.tsapko 7 лет назад

    Hi, looks like using context.WithTimeout somehow tears down TCP half-connection from client to server, that's why you got context closed on the server side. I didn't get how it closes the half-connection. But the question is why context.WithCancel does not tear down TCP half-connection after invoking cancel() ?

  • @codesworth
    @codesworth 7 лет назад

    This helped me understand the context package much better, thank you!

  • @faroukfaiz8396
    @faroukfaiz8396 2 года назад

    This is some good quality content!

  • @sayansikdar4385
    @sayansikdar4385 3 года назад

    where can I find the codes which are written here?

  • @kauehmoreno8967
    @kauehmoreno8967 5 лет назад

    I got a doubt. When u write a handler with select case, context will be cancel only because your time.After are holding execution and than

    • @kauehmoreno8967
      @kauehmoreno8967 5 лет назад

      I got it!! It will be able to run on a different goroutine returning value and catch it into select statement

  • @johnbalvin5401
    @johnbalvin5401 6 лет назад

    how do I set up visual studio to add the package library while I writting code? I always need to do it for myself and is anoying

  • @kamal-xd7id
    @kamal-xd7id 7 лет назад

    Learned Context in one go, without even pausing a single sec. :) btw which editor you are using and i saw you have some template like hand -> f(w http.Responsewrite, r *http.Request), how to do it?

  • @AndrewMinkinGen1us2k
    @AndrewMinkinGen1us2k 7 лет назад

    Hey. Now I know more about context. I never thought that I have context in net/http package and it was a surprise for me. Thank you!

  • @fuadolatunji9316
    @fuadolatunji9316 2 года назад

    What vscode theme is this?

  • @vs4vijay
    @vs4vijay 4 года назад

    One of the best explanation!!! Thanks.

  • @john_rambo_27098
    @john_rambo_27098 6 лет назад +1

    Beautiful, Excellent, Mind Blowing, Priceless

  • @adnanrashid6743
    @adnanrashid6743 4 года назад

    Really enjoyed the explanation, very clear 👍🏽

  • @GertCuykens
    @GertCuykens 7 лет назад

    Nice, learnt allot. PS can you also give the reason behind values not propagating like cancel please?

  • @tanoybhowmick8715
    @tanoybhowmick8715 4 года назад

    Please keep the good work up. So good.

  • @mehditorkamani9890
    @mehditorkamani9890 5 лет назад

    Amazing... Short and sweet!

  • @publicuser993
    @publicuser993 4 года назад

    That's what i needed.
    BIG THANK YOU

  • @AbdulMannan-rv5yx
    @AbdulMannan-rv5yx 3 года назад

    Really nice, clear my head lots on this package

  • @Simon-xi8tb
    @Simon-xi8tb 2 года назад +1

    where is the sleepAndTalk fn ?

  • @easternsunking255
    @easternsunking255 6 лет назад

    what will happen if the both the parent routine and child routine cancel the context at the same time. and if the parent routine has more than one routine like Ca and Cb for example, both the Ca and Cb use the context from parent routine P, if the P cancelend, both Ca and Cb will canceled? if only Ca canceled, then P and Cb will not be notified ?

    • @JustForFunc
      @JustForFunc  6 лет назад

      Closing a channel doesn't notify a single receiver (unlike sending elements) instead it unlocks every goroutine blocked receiving from it

    • @easternsunking255
      @easternsunking255 6 лет назад

      many thanks,after watch your next episonde(implement the context), I got it!

  • @unknownknowns420
    @unknownknowns420 2 года назад

    phenomenal explanation, thanks!

  • @susisorglos3215
    @susisorglos3215 7 лет назад

    Hey, very nice video! Could you make an episode about you vscode setup and the extensions you are using? Thanks!

  • @MD-xx6ob
    @MD-xx6ob 6 лет назад

    You've done a great job ! You're accent is very clear for a frenchie like me

    • @JustForFunc
      @JustForFunc  6 лет назад +2

      Merci beaucoup, je fais mon mieux

  • @sphaniy
    @sphaniy 6 лет назад

    Francesc, Did you do the episode on the internals of the context package?

    • @JustForFunc
      @JustForFunc  6 лет назад

      Yup, literally the episode after this one

  • @nwjlions
    @nwjlions 7 лет назад

    Really informative video. Thanks Francesc.

  • @phillippotter1359
    @phillippotter1359 4 года назад

    Really helpful video, thank you dude, keep up the great work!

  • @redsnakeintown
    @redsnakeintown 6 лет назад

    Couldnt figure out what you did in the Decorate. I think I need some sleep..

    • @RandomShowerThoughts
      @RandomShowerThoughts 5 лет назад

      it was basically a middle ware which adds in a request id into the context and returns the next function as a call

  • @Waffle-ish
    @Waffle-ish 3 года назад

    Disclaimer: kinda new to golang XD
    What do you mean by "defining a request without using tags?"

  • @jonathanfernandes3327
    @jonathanfernandes3327 5 лет назад

    How come this code works even though the select isn't in a for loop?

    • @DudeMcDuderson
      @DudeMcDuderson 5 лет назад +2

      The select statement waits for a channel to return a value, unless you have a default case. Having a default case implies you're doing some work and will come back to check the channels again, in which case your select would be wrapped in a for loop to enable it to be called again. Otherwise you only care about whichever channel returns data first, say a timeout or a cancel.

    • @jonathanfernandes3327
      @jonathanfernandes3327 5 лет назад

      @@DudeMcDuderson That helped a lot, thanks Dude!

    • @princeofexane
      @princeofexane Год назад

      @@DudeMcDuderson Thanks a lot.

  • @matheusaraujo4495
    @matheusaraujo4495 2 года назад

    Very nice explanation! Thanks

  • @ericb.9777
    @ericb.9777 7 лет назад

    Very clear, as always, GO on

  • @SaxonChuang
    @SaxonChuang 4 года назад +2

    I have no idea about how the function sleepAndTalk know we cancelled

    • @KotBinary
      @KotBinary 4 года назад +1

      I had the same question. So, I googled this: gist.github.com/astenmies/2f180213d310aa16b4b8c4e637be9441

    • @SaxonChuang
      @SaxonChuang 4 года назад +1

      @@KotBinary thanks :)

  • @jayeshthamke7860
    @jayeshthamke7860 4 года назад

    Exceptional work!

  • @keepondev
    @keepondev 4 года назад

    Amazing explanation! thank you so much

  • @darrensapalo
    @darrensapalo 3 года назад

    Incredible talk.

  • @luvpranay
    @luvpranay 3 года назад

    Learning Golang from Bayer Mayfield. The best

  • @theden111111
    @theden111111 7 лет назад +3

    which font you use?

    • @AntonGalitsyn
      @AntonGalitsyn 7 лет назад

      it's github.com/tonsky/FiraCode

    • @AtakanOzceviz
      @AtakanOzceviz 7 лет назад

      github.com/tonsky/FiraCode

    • @wanderingeek
      @wanderingeek 7 лет назад

      You sure? Sure looks a lot like Source Code Pro [github.com/adobe-fonts/source-code-pro]

    • @izakmarais1766
      @izakmarais1766 7 лет назад +1

      Yes, Frances mentioned it in the comments of an earlier video. FiraCode has programming ligatures, which you can see in the channel symbol (

  • @DreammzShow
    @DreammzShow 4 года назад

    Thank you for the great videos. This is really helpful.

  •  7 лет назад

    What editor are you using?

    • @wanderingeek
      @wanderingeek 7 лет назад

      He is using Visual Studio Code [code.visualstudio.com/] with the Go plugin [code.visualstudio.com/docs/languages/go]

  • @paragkamble
    @paragkamble 3 года назад

    Thanks Very clear explanation.

  • @michalvyskocil
    @michalvyskocil 5 лет назад

    Hi, amazing stuff! I was still struggling on how to use context skimming the official docs. However this is simply awesome. Especially thanks for showing that you can't send context values across network.That would be stupid idea anyway :-)

  • @davidagyakwa288
    @davidagyakwa288 3 года назад

    Deep dive in context ...id be glad

  • @AnhNguyen-vu7mc
    @AnhNguyen-vu7mc 7 лет назад

    Hey Francesco, huge thanks for your series of videos. was wondering if you can post the code repo on github

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Anh Nguyen it's on GitHub.com/campoy/justforfunc

  • @mehradsadeghi
    @mehradsadeghi 3 года назад

    Thank you for this video.

  • @nolliepoper
    @nolliepoper 7 лет назад

    This was super helpful, thank you.

  • @grantseltzerrichman2051
    @grantseltzerrichman2051 7 лет назад

    This was great, thanks so much!

  • @sweetmoment8196
    @sweetmoment8196 5 лет назад

    Just one word, Awesome

  • @ericnyamu5249
    @ericnyamu5249 5 лет назад

    thanks Thor.I now understand Go better

  • @chevs11
    @chevs11 4 года назад

    That was very useful, thanks!

  • @MrGreen-kq4ds
    @MrGreen-kq4ds 4 года назад

    amazing video , thank you!

  • @jojoross
    @jojoross 4 года назад

    useing a function (sllepAndTalk) you created for half of the video ,and not showing how that function worked was a waste of my time.
    thank you for frustrating me back to the doc.

  • @AlexTitarenko87
    @AlexTitarenko87 6 лет назад

    excellent explanation

  • @ColmMalone
    @ColmMalone 4 года назад

    Who's here from the Aug 20th Go Time podcast?
    BTW at 21:00 - since go1.13 - you can now do this in one call with: golang.org/pkg/net/http/#NewRequestWithContext

  • @Oswee
    @Oswee 6 лет назад

    I really, really, really would like to see complete series about how to create IDIOMATIC Client Server WEB application with most common CRUD operations using gRPC and MySQL. Client and Server should be just simple Go programs. Would like to see: IDIOMATIC Directory/File organization in context of github.com/myusername/. gRPC service interface, and message/+field idiomatic naming and organizing into packages. Package +nested package importing. Compiling nested .proto's. TLS secured gRPC communication. Idiomatic endpoint URL constructions. Context. Displaying in browser - single record, list of records, single record + list. Submitting form, updating record, creating nested records - like, when customer is created, also some log record in the same DB is created pointing to the same customer (tx). And so on so on.
    Basically, EVERY beginner want to see complete IDIOMATIC example of writing production ready basic DD web-page.
    Nobody is teaching this. 98% of tutorials and books teaching the easiest way - Just mess everything into main.go and use mock data! This is total BS! This is not how good things should be teached.
    It is much better when you see, how great foundation looks like and then starting to tweak, and to learn all those used patterns in details. When you have no context in head, it is impossible to learn right way. Iterating thru the trial & fail is way to learn for sure, but it is not the most effective! It just wastes too much human time.
    YES - this kind of tutorial will take time to record. But this will be the SINGLE PERFECT TUTORIAL in the whole f*g WEB.

  • @SergeySaraev-xe4fl
    @SergeySaraev-xe4fl 7 лет назад

    Very Nice! Thatk you Francesc!

  • @bathaivan4323
    @bathaivan4323 4 года назад

    very helpful, thanks very much

  • @ffridiejr
    @ffridiejr 7 лет назад

    Very helpful. Thanks.

  • @garciajero
    @garciajero 6 лет назад

    this is so good.

  • @pnsvinodkumar
    @pnsvinodkumar 5 лет назад

    super awesome!

  • @jojjan93
    @jojjan93 6 лет назад

    Great video francesca ;)

    • @JustForFunc
      @JustForFunc  6 лет назад

      That's not my name

    • @jojjan93
      @jojjan93 6 лет назад

      JustForFunc: Programming in Go hehe 😁

    • @jojjan93
      @jojjan93 6 лет назад

      JustForFunc: Programming in Go i know, i just couldnt remember which video it was where at the end someone couldnt say your name :)

  • @TylerShawful
    @TylerShawful 3 года назад

    That poor plant in the background needs water

  • @rahulmg05
    @rahulmg05 6 лет назад

    Can you please make a video on Interceptors. :)

    • @JustForFunc
      @JustForFunc  6 лет назад

      Sure ... what do you mean by interceptor?

    • @rahulmg05
      @rahulmg05 6 лет назад

      @@JustForFunc They are like middlewares. It does come with the standard grpc package.
      github.com/grpc/grpc-go/blob/master/interceptor.go. The standard package has a big limitation. Middleware/Interceptor Chaining is not allowed.
      There are third party packages to accommodate chaining. This one is pretty popular --> github.com/grpc-ecosystem/go-grpc-middleware
      The concept looks very simple but it might get a little confusing when you dive deep into it. Would be helpful if you make a video. Thank you :)

    • @JustForFunc
      @JustForFunc  6 лет назад

      Oh so you mean grpc interceptors specifically!

    • @rahulmg05
      @rahulmg05 6 лет назад

      @@JustForFunc Exactly. I understand there are quite a few documents (should I say incomplete documents) on the internet where people keep comparing interceptors to middlewares, explain the differences between the standard grpc interceptors and go-grpc-middleware but do not go into the details. For someone who already know the basics of grpc, interceptors in grpc is a great way to advance his/her knowledge. The way you explain things is priceless, so thought of requesting you to do a video on it :-).