Advanced Golang: Channels, Context and Interfaces Explained

preview_player
Показать описание
Today, I'll provide a simple breakdown of channels, context and interfaces in Golang. I'll show examples of why they are useful and how to properly use them in the real world.

0:00 Intro
0:17 Channels
8:35 Context
13:55 Interfaces
21:53 Conclusion

Channels are a safe way of transferring data between goroutines without using a mutex. You can send data to a channel in one goroutine, then consume data from the same channel in another goroutine. By default, a channel does not have space to store data, so you must simultaneously send and receive data from the channel to avoid a deadlock. A buffered channel allows you to allocate space to temporarily store data in the channel.

Context is an object that can be safely passed to multiple goroutines to provide a way to implement a timeout or cancellation to a function. 3rd party libraries that make HTTP requests or database requests typically have support for providing your own context so you cancel those operations.

Interfaces are a great way to enforce a blueprint for what your app can do, similar to object oriented programming. For example, there are many different types of bank accounts, but you can use a single interface to interact with all of them: GetBalance(), Deposit() and Withdraw(). This makes your high-level code easier to work with because the implementation is abstracted away.
Рекомендации по теме
Комментарии
Автор

this guy just chilling on his bed while explaining complex staff, loving it haha

whyyuou
Автор

Ryan you probably are already aware of it, but you have such a talent in explaining stuff. Thanks for your work. Keep exploring Golang please

robimalco
Автор

Love it, talking about advanced software concepts while chilling on his bed. Legend 👏

typ_cratz
Автор

This video is a gem, It would have been awesome if you could have a series for advanced golang. I am sure other viewers would want that too !

David-xynw
Автор

Your voice is ASMR but the best part is you know what you're talking about and how to explain it.

esra_erimez
Автор

I've read several books on Go but your explanations have been clearer and more concise to me. I especially like your description of (unbuffered) channels as being portals that don't store anything and why they could result in a deadlock. I never really understood that from my readings until you explained it.

jamestk
Автор

Ryan- you have a natural ability for simply explaining complex topics. Good job!

exxzxxe
Автор

your casual style makes information so much more accessible. i subbed!

erichshan
Автор

I love your isolation method of explaining code

ngjimmy
Автор

Hey Ryan this is great quality content! Please do more Go videos as there’s not much on YouTube. Keep up with the good work!

johnnychang
Автор

Dude, your explanation is crystal clear, very specifics and more importantly no blabbering. You should put more tutorials or create a course in udemy man...

senthilramalingam
Автор

Amazing video series for go, I love hearing advanced topics in a new language, that I can carry over from previous ones I know.🎉❤

vanjastojanovic
Автор

Damn, I like how this guy explains things. He oozes experience just from how he talks, and doesn't look like he's reading from an off screen document. Like he was working on some go code and thought it would be nice to share it in a video. He also doesn't just regurgitate what is in the docs like others.

salvaje
Автор

the most simple way and complex at the same time i have seen, awesome explanation. thanks.

thiagoantunes
Автор

Man, excellent video. Nice to see someone put together solid examples and walk through them well.

amesasw
Автор

I hadn't touched Go in a couple years, and this video was a perfect refresher to jog my memory on the operation of channels. Nice job!

bruceleeharrison
Автор

Great tutorial Ryan. Finally I can actually understand contexts in Go.

rshraddha
Автор

We need more of golang, your content is superb and easy to understand, very practical examples.

jondoe
Автор

16:59
damn, that was smooth af
"We don't want to allow the user to withdraw too much unless their name is Ryan 🤣"

majdbehnana
Автор

Love how you explain the concepts. Keeping them simply and clear.
Thanks a lot for the great work

VadimCebotari