avatarAiden (Illumination Gaming)

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5070

Abstract

do that:</p><div id="2e8b"><pre>eventHandler<span class="hljs-selector-class">.Handle</span>(event1, <span class="hljs-built_in">ExampleMiddlewareFoo</span>(<span class="hljs-built_in">ExampleMiddlewareBar</span>(handle)))</pre></div><h1 id="a8a5">Managing Events with Handlers and Middleware</h1><p id="f869">Most articles I read explain how to use this design pattern; this one deals with implementing the internal logic. So let's start coding.</p><p id="35c4">The full code for this article can be found <a href="https://github.com/xNok/slack-go-demo-socketmode/blob/main/examples/middleware/main.go">here</a> to help you follow along.</p><h2 id="0f88">Designing events</h2><p id="b622">First, we are going to enumerate the list of events that our system can handle. The way we create enumeration in Go is a bit different than in other programming languages. In Go, we are going to use a set of constants sharing the same <code>type</code>. Here I define a type <code>EventType</code>that represents a string with the event's name.</p><div id="b181"><pre>// <span class="hljs-keyword">type</span> <span class="hljs-type">used </span>to enumerate events <span class="hljs-keyword">type</span> <span class="hljs-type">EventType </span>string</pre></div><div id="4817"><pre>const ( event1 EventType <span class="hljs-operator">=</span> <span class="hljs-string">"event1"</span> event2 EventType <span class="hljs-operator">=</span> <span class="hljs-string">"event2"</span> )</pre></div><p id="e041">Next, we define the event itself. In our example, the<code>Event</code> as a type which can be selected among the list of <code>EventType</code> created above.</p><div id="2bc9"><pre><span class="hljs-keyword">type</span> <span class="hljs-type">Event</span> struct { <span class="hljs-type">Type</span> <span class="hljs-type">EventType</span> <span class="hljs-type">Data</span> interface{} }</pre></div><h2 id="df6c">Create an event sender (for test purpose)</h2><p id="60aa">To test our system, we will need to create a small function to send events every 2s. Each<code>Event</code> is transmitted via a <a href="https://tour.golang.org/concurrency/2">channel</a> and, the <code>eventSender</code> below sends a random <code>Event</code> of type <code>event1</code> or <code>event2</code> to a channel.</p><blockquote id="53f3"><p><i>Channels are a type which you can send and receive values, they are great for communication among goroutines. In other words, there are perfect for sending and receive event through your application.</i></p></blockquote><div id="ffd1"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">eventSender</span><span class="hljs-params">(c <span class="hljs-keyword">chan</span> EventType)</span></span> {</pre></div><div id="7f57"><pre> for { // Send <span class="hljs-selector-tag">a</span> random event <span class="hljs-selector-tag">to</span> the channel rand<span class="hljs-selector-class">.Seed</span>(<span class="hljs-selector-tag">time</span><span class="hljs-selector-class">.Now</span>()<span class="hljs-selector-class">.Unix</span>()) events := []EventType{ event1, event2, } n := rand.<span class="hljs-built_in">Int</span>() % <span class="hljs-built_in">len</span>(events)</pre></div><div id="6101"><pre> c <- events[n] <span class="hljs-comment">// send event to channel</span></pre></div><div id="5285"><pre> // <span class="hljs-keyword">wait</span> a <span class="hljs-built_in">bit</span> <span class="hljs-built_in">time</span>.Sleep(<span class="hljs-number">2</span> * <span class="hljs-built_in">time</span>.Second) } }</pre></div><h2 id="000c">Handler and dispatcher</h2><p id="e562">We first need a struct to hold the list of events we want to listen to and which function to call whenever that event is transmitted. This struct also contains the channel used for communicating events.</p><div id="280d"><pre><span class="hljs-comment">// Create a struct to hold config</span> <span class="hljs-comment">// And simplify dependency injections</span> <span class="hljs-keyword">type</span> EventHandler <span class="hljs-keyword">struct</span> { <span class="hljs-comment">// Event channel</span> Events <span class="hljs-keyword">chan</span> Event <span class="hljs-comment">// hold the registedred event functionss</span> EventMap <span class="hljs-keyword">map</span>[EventType][]<span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">(Event)</span></span> }</pre></div><p id="aa6c">Next, we need to provide an initializing constructor for our <code>EventHandler</code>.</p><div id="a4ed"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">NewEventHandler</span><span class="hljs-params">()</span></span> *EventHandler { eventMap := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">map</span>[EventType][]<span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">(Event)</span></span>) event

Options

s := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> Event)</pre></div><div id="78bb"><pre> return <span class="hljs-variable">&</span>EventHandler<span class="hljs-punctuation">{</span> <span class="hljs-symbol"> Events:</span> events, <span class="hljs-symbol"> EventMap:</span> eventMap, <span class="hljs-punctuation">}</span> <span class="hljs-punctuation">}</span></pre></div><p id="98fe">Then, we can create our <code>Handle</code> function that associates the event with a callback function.</p><div id="308c"><pre><span class="hljs-comment">// register the handler function to handle an event type</span> func (h *EventHandler) <span class="hljs-built_in">Handle</span>(e EventType, f <span class="hljs-built_in">func</span>(Event)) { h<span class="hljs-selector-class">.EventMap</span><span class="hljs-selector-attr">[e]</span> = <span class="hljs-built_in">append</span>(h<span class="hljs-selector-class">.EventMap</span><span class="hljs-selector-attr">[e]</span>, f) }</pre></div><p id="e42a">Finally, we create the <code>EventDispatcher</code> function, the core of this mechanism. The <code>EventDispatcher</code>process any event sent to a channel, check its type, and if any function has been registering for that type, we call all registered functions.</p><div id="6597"><pre><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(h *EventHandler)</span></span> EventDispatcher() { <span class="hljs-keyword">for</span> evt := <span class="hljs-keyword">range</span> h.Events { log.Printf(<span class="hljs-string">"event recieved: %v"</span>, evt) <span class="hljs-keyword">if</span> handlers, ok := h.EventMap[evt.Type]; ok { <span class="hljs-comment">// If we registered an event</span> <span class="hljs-keyword">for</span> _, f := <span class="hljs-keyword">range</span> handlers { <span class="hljs-comment">// exacute function as goroutine</span> <span class="hljs-keyword">go</span> f(evt) } } } }</pre></div><h1 id="13e4">Using our system</h1><p id="4d4e">Everything is ready; we can start using our event handling system.</p><ol><li>Instantiate our event Handler</li><li>Register which event to listen to and what function to callback</li><li>Start the event sender</li><li>Start the event dispatcher</li></ol><div id="62ab"><pre><span class="hljs-keyword">func</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span> {</pre></div><div id="5b09"><pre> <span class="hljs-variable">eventHandler</span> := <span class="hljs-function"><span class="hljs-title">NewEventHandler</span>()</span></pre></div><div id="d244"><pre> eventHandler.Handle(event1, <span class="hljs-keyword">func</span><span class="hljs-params">()</span> { <span class="hljs-built_in">log</span>.Printf(<span class="hljs-string">"event Handled: %v"</span>, event1) })</pre></div><div id="5c56"><pre> <span class="hljs-variable">go</span> <span class="hljs-function"><span class="hljs-title">eventSender</span>(<span class="hljs-variable">eventHandler.Events</span>)</span></pre></div><div id="30f2"><pre> eventHandler<span class="hljs-selector-class">.EventDispatcher</span>()</pre></div><div id="9bf2"><pre>}</pre></div><p id="e590">The result should be along those lines:</p><figure id="5ee7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_D-GCRSu3K8CgTBXewJjJQ.gif"><figcaption></figcaption></figure><p id="19d6">Since we only handle an event of type <code>event1</code>, only <code>event1</code> shows as <code>Hansled</code>. All is good!</p><p id="d48a">The full code for this article can be found <a href="https://github.com/xNok/slack-go-demo-socketmode/blob/main/examples/middleware/main.go">here</a>.</p><h1 id="6f5e">Interesting Articles tackling the same topic</h1><ul><li><a href="https://drstearns.github.io/tutorials/gomiddleware/">Middleware Patterns in Go</a></li><li><a href="https://sathishvj.medium.com/web-handlers-and-middleware-in-golang-2706c2ecfb75">Web Handlers and Middleware in GoLang</a></li><li><a href="https://readmedium.com/lightweight-event-management-implemented-by-go-a654d59ac65">Lightweight event management implemented by Go</a></li><li><a href="https://readmedium.com/the-7-most-important-software-design-patterns-d60e546afb0e">The 7 Most Important Software Design Patterns</a></li></ul><p id="13e7"><i>Do you want <b>unlimited access</b> to all my content and many other writers’ content on Medium? Consider using my affiliate link to <a href="https://couedeloalexandre.medium.com/membership">become a Medium member today</a></i></p><h2 id="853a">Further reads</h2> <figure id="81d2"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://couedeloalexandre.medium.com/embed/list/3f9d03f2cb8f" allowfullscreen="" frameborder="0" height="184" width="undefined"> </div> </div> </figure></iframe></div></div></figure></article></body>

Gaming News

Major Balance Changes Are Incoming in Overwatch 2

Hero balance changes have been confirmed by Overwatch in Season 6.

Image by cromaconceptovisual from Pixabay

In some of my earlier posts, I’ve chatted about all sorts of stuff concerning Overwatch. You can find the links to those down below.

But right now, I’m gonna dive into Overwatch 2 and spill the beans on what’s cookin’ with the hero balance tweaks for Season 6.

Why is Overwatch so popular?

Overwatch is like the rockstar of the gaming world, and let me tell you, it ain’t just about the slick graphics and badass characters — there’s a whole lot more to it. I’m about to spill the beans on why Overwatch has taken the gaming scene by storm.

First off, it’s all about the diversity in heroes, man. I mean, you’ve got this eclectic bunch from all walks of life — from a gorilla scientist to a DJ healer.

Each hero is like a unique piece of the puzzle, bringing their own skills, personality, and backstory. You can be a gunslinging cowboy one minute, and a high-tech ninja the next. It’s like a buffet of playstyles, and that keeps things fresh and exciting.

The gameplay is as addictive as your grandma’s secret chocolate chip cookies. It’s this intense mix of teamwork and individual skill that’s like a match made in gaming heaven.

You can’t just go Rambo-style and expect to win — you’ve gotta strategize, communicate, and work together with your team to secure the victory. And let’s not forget those clutch moments when you pull off an epic play that makes your heart race faster than a caffeinated hummingbird.

Blizzard, the masterminds behind Overwatch, know how to throw a party. They’re always cooking up something new — from seasonal events with crazy skins, new maps, new game modes, and those upcoming story missions.

You never know what they’re gonna drop next, and that keeps players on the edge of their seats. It’s like Christmas morning, except it happens more often and with fewer socks.

But perhaps the secret sauce of Overwatch’s popularity is the community. You’ve got fan art, cosplays, memes, and a bunch of other cool stuff that brings players together. It’s like joining a big, quirky family where everyone speaks the same language — the language of Overwatch.

And let’s not forget the e-sports scene. Watching the pros go at it is like watching the Super Bowl of gaming, and it adds a whole new level of excitement.

Hero balance changes in Season 6?

Overwatch 2 is shaking things up in Season 6 with some hero adjustments you’ll want to know about. Lifeweaver’s Tree of Life ability is getting a nice buff, while Kiriko’s Protection Suzu is getting a nerf.

Oh, and Cassidy’s Magnetic Grenade range is taking a hit, but Mercy’s damage boost is getting cranked up a notch.

Get ready for the big Invasion update in Overwatch 2! This update is dropping some cool stuff, like PvE story missions, a player progression system, hero adjustments, and even two new Flashpoint maps.

Blizzard’s saying Season 6 is going to be massive, and they’re throwing a new support hero into the mix to stir up the meta.

In a recent blog post, Overwatch 2’s game director, Aaron Keller, spilled the beans on the upcoming season. Brace yourself for changes to some support heroes, like Kiriko and Mercy.

Kiriko’s Protection Suzu will heal a bit less, but it’ll give a burst of healing when shaking off negative effects from allies. Mercy’s damage boost is getting dialed back from 30 percent to 25 percent — looks like they’re toning down her offensive powers.

Speaking of changes, Lifeweaver is in for some serious upgrades. Rejuvenating Dash is going to give more health, and Tree of Life’s healing is turning into Overhealth for buddies. But Cassidy’s Magnetic Grenade? Yeah, that’s getting a bit of a range nerf, set at 1.5 seconds.

Kiriko and Mercy have been fan favorites for a while now, making gameplay exciting with their versatile skills. They’re all about speed, utility, and top-tier healing. But here’s the twist — their popularity might dip a bit with the arrival of the Invasion update on August 10th.

Mercy’s been a hot topic, with her ability to turn the tide of battle with those overpowered damage boosts. She’s got healing chops and a knack for shifting the balance in matches.

Even though she’s not an AoE healer, Mercy’s agility and offense make her a solid fit for many teams. Kiriko, on the flip side, is a powerhouse support hero, packing a punch to take control of matches.

Final Words

The community’s bound to buzz with reactions when these support hero changes hit on August 10th.

Until then, all we can do is sit back and wait for the bulk load of content we’re about to receive in Season 6.

If you enjoy my posts and would like to stay updated on the latest gaming-related news, technology advancements, design trends, and social media insights, I invite you to follow my profile.

I will continue to share my thoughts and insights on a wide range of topics in the world of entertainment and technology.

With that being said, thank you for reading my post, and have a good one.

If you are interested in email marketing and earning a bit of cash, I wrote an article about it and created a YouTube video.

Here is everything I wrote last month:

Here are a few of my previous stories relating to Overwatch I believe you will enjoy:

References

Overwatch 2 Season 6 Patch: Release Date, Hero Balance Changes, More.

Overwatch 2 Reveals Major Balance Changes For Lifeweaver, Kiriko, Mercy, and More.

Have you tried Cliqly yet?

About Me

I write articles in my field covering gaming, film-making, social media, and design. I am also a YouTuber. Thank you for subscribing to my account to get notifications when I post on Medium. I also created a new website to share my content for free and promote stories of writers contributing to my publications on Medium. I also have a Substack newsletter. Let’s connect on Twitter and LinkedIn.

I own two publications on Medium. One for video gamers and another for YouTubers and Podcasters. I also support Illumination Integrated Publications as a volunteer editor and participate in collaborative activities in the Slack Workspace. Writer applications for my publications can be sent via this weblink. Please add your Medium ID.

If you are new to Medium, you may join via my referral link. You may also consider being a Vocal+ member to monetize your content. I write for both platforms and repurpose my content to reach a larger audience. Here is more information about Vocal Media. I also enjoy email marketing using Cliqly.

This post includes referral links.

Gaming
Games
Virtual Reality
Social Media
Gaming News
Recommended from ReadMedium