<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Golang on CyberSpy</title>
    <link>https://cyberspy.io/categories/golang/</link>
    <description>Recent content in Golang on CyberSpy</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 10 Dec 2019 09:55:44 -0500</lastBuildDate>
    <atom:link href="https://cyberspy.io/categories/golang/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Getting func(y) with Channels</title>
      <link>https://cyberspy.io/code/channelfuncs/</link>
      <pubDate>Tue, 10 Dec 2019 09:55:44 -0500</pubDate>
      <guid>https://cyberspy.io/code/channelfuncs/</guid>
      <description>&lt;h2 id=&#34;heres-a-little-golang-puzzle&#34;&gt;Here&amp;rsquo;s a little golang puzzle&lt;/h2&gt;&#xA;&lt;p&gt;Take a look at the function below that computes a mystery value for the function $f(x)$. Any idea what the function is? Take a close look at the first line where we create a channel. Notice that the channel isn&amp;rsquo;t some boring &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt; channel. No, this is a channel of type &lt;code&gt;func(int, chan int, chan bool)&lt;/code&gt;. Wait what??? That&amp;rsquo;s right, this channel takes a function that takes an integer and two channels as function parameters. We define such a function, &lt;code&gt;x&lt;/code&gt;, right aftewards.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Once Upon a Reflection: Looking Deeper into Golang reflection</title>
      <link>https://cyberspy.io/articles/reflectinggo/</link>
      <pubDate>Mon, 04 Dec 2017 17:36:31 -0500</pubDate>
      <guid>https://cyberspy.io/articles/reflectinggo/</guid>
      <description>&lt;h3 id=&#34;i-often-reflect-upon-my-code&#34;&gt;I often &lt;em&gt;reflect&lt;/em&gt; upon my code&amp;hellip;&lt;/h3&gt;&#xA;&lt;p&gt;One of the coolest features of the Golang programming language is the &lt;a href=&#34;https://golang.org/pkg/reflect/&#34;&gt;reflect package&lt;/a&gt;. As the package documentation states at the onset of the package:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;On the surface, that all sounds pretty straight-forward. But when you start to think about the types of objects (literally) that you might reflect upon, things can get interesting pretty quickly. It&amp;rsquo;s one thing to dynamically get the type of an object like an &lt;code&gt;Int&lt;/code&gt;, and then extract it&amp;rsquo;s value. But what about dynamically getting access to Methods inside a &lt;code&gt;struct&lt;/code&gt; and then calling it with values created dynamically from an a-priori signature, returning values and extracting those values programatically? Rather quickly, the power of reflection can become overwhelming and even confusion. Moreover, appropriate use-cases of reflection should be well thought out so that we aren&amp;rsquo;t simply&#xA;getting too clever for our own good.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Shoutout1</title>
      <link>https://cyberspy.io/quote/shoutout1/</link>
      <pubDate>Sat, 02 Dec 2017 10:36:00 -0500</pubDate>
      <guid>https://cyberspy.io/quote/shoutout1/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;Wanna &lt;strong&gt;learn&lt;/strong&gt; you some Go? &lt;em&gt;&lt;strong&gt;&lt;a href=&#34;https://golangbot.com/learn-golang-series/&#34;&gt;Tutor&lt;/a&gt;&lt;/strong&gt;&lt;/em&gt; up over here!&lt;/p&gt;&#xA;&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>Go Get Interfaced: Enums in Golang</title>
      <link>https://cyberspy.io/code/gogetinterfaces/</link>
      <pubDate>Sat, 02 Dec 2017 09:38:42 -0500</pubDate>
      <guid>https://cyberspy.io/code/gogetinterfaces/</guid>
      <description>&lt;h3 id=&#34;golang-interfaces-and-enums&#34;&gt;Golang, Interfaces, and Enums&lt;/h3&gt;&#xA;&lt;p&gt;So here&amp;rsquo;s a nice golang idiom that I ran across years ago that I found generally useful. Golang, unlike languages like &lt;strong&gt;c&lt;/strong&gt; doesn&amp;rsquo;t natively support enumerations. Instead, constants typically are used when creating a list of enumerations. But, go is a strongly-typed language, so we can do better than simply using constants - we can &lt;em&gt;type&lt;/em&gt; our enumeration with the use of a &lt;code&gt;type&lt;/code&gt; declaration.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-golang&#34; data-lang=&#34;golang&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;type&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;DogState&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;uint&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;By defining a type for our enumeration, we can consistently pass and return typed-values among our functions operating on our enumeration. Okay, that&amp;rsquo;s all well and good, but what happens when we want to go between &lt;code&gt;uint&lt;/code&gt; values and &lt;code&gt;string&lt;/code&gt; representations of those values; a commonly used paradigm when working with enumerations. One approach would have us write mapping functions that might &lt;code&gt;switch&lt;/code&gt; among the values to return a &lt;code&gt;string&lt;/code&gt;. Or, when going from a &lt;code&gt;string&lt;/code&gt; name of an enumeration to the &lt;code&gt;uint&lt;/code&gt; value, we might use a &lt;code&gt;map[string]&lt;/code&gt;. That&amp;rsquo;s a doable implementation, but there&amp;rsquo;s an easier, and more idiomatic way.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Gogo</title>
      <link>https://cyberspy.io/code/gogo/</link>
      <pubDate>Wed, 29 Nov 2017 20:57:33 -0500</pubDate>
      <guid>https://cyberspy.io/code/gogo/</guid>
      <description>&lt;h3 id=&#34;here-we-gogo&#34;&gt;Here we &lt;em&gt;gogo!&lt;/em&gt;&lt;/h3&gt;&#xA;&lt;p&gt;Years ago, I wrote an interesting article that I thought might be worth re-posting (and revising) here on my blog. For a while&#xA;I got into programming in &lt;a href=&#34;https://golang.org&#34;&gt;golang&lt;/a&gt; and in the early going (pun-alert!), there were a lot of idioms that were not well understood by a &lt;em&gt;noob&lt;/em&gt;. One of those paradigms was &lt;em&gt;channels, go-routines, and signals&lt;/em&gt; used simultaneously. Taken separately, they are more easily understood. But when taken together, there can be some confusion. In this article, I address how to properly establish a signal-handler and a channel to terminate go-routines when the user interrupts the program with a signal such as &lt;code&gt;ctrl-c&lt;/code&gt; or &lt;code&gt;kill(1)&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
