<?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 Samarthya</title><link>https://samarthya.me/categories/golang/</link><description>Recent content in Golang on Samarthya</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© Samarthya 2018-2026. All rights reserved.</copyright><lastBuildDate>Thu, 07 Jul 2022 12:00:00 +0000</lastBuildDate><atom:link href="https://samarthya.me/categories/golang/index.xml" rel="self" type="application/rss+xml"/><item><title>Go Modules</title><link>https://samarthya.me/posts/go-modules/</link><pubDate>Thu, 07 Jul 2022 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/go-modules/</guid><description>&lt;p&gt;If you are like me and getting errors while trying to compile your go lang code without having a &lt;code&gt;go.mod&lt;/code&gt; in &lt;code&gt;v1.18&lt;/code&gt;&lt;/p&gt;&#10;&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;package src is not in GOROOT (/usr/local/Cellar/go/1.18.3/libexec/src/src)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;p&gt;Remember you have overlooked a basic change that happened post &lt;code&gt;1.16&lt;/code&gt;&lt;/p&gt;</description></item><item><title>Kaniko: Jenkins Pipeline</title><link>https://samarthya.me/posts/kaniko-jenkins-pipeline/</link><pubDate>Fri, 11 Feb 2022 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/kaniko-jenkins-pipeline/</guid><description>&lt;p&gt;So there are many things I have been simultaneously trying to learn &amp;amp; one of those is to learn how you can configure a pipeline&lt;/p&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; Read more about Pipeline as Code (PaC)&#10;&lt;/div&gt;&#10;&#10;&#10;&lt;h2 class="relative group"&gt;Objectives&#10; &lt;div id="objectives" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#objectives" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h2&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Learn Jenkins deployment on Kubernetes&lt;/li&gt;&#10;&lt;li&gt;Learn Jenkins Kubernetes Plugin&lt;/li&gt;&#10;&lt;li&gt;Learn Jenkins Pipeline (&lt;code&gt;Declarative&lt;/code&gt;)&lt;/li&gt;&#10;&lt;li&gt;How to build and deploy images in Kubernetes cluster&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;All right, with so many monkeys on my back I had to do things the way I know it works for me.&lt;/p&gt;</description></item><item><title>Fun with `goroutines`</title><link>https://samarthya.me/posts/fun-with-goroutines/</link><pubDate>Fri, 26 Feb 2021 08:36:20 +0000</pubDate><guid>https://samarthya.me/posts/fun-with-goroutines/</guid><description>&lt;p&gt;Channels are way of communication between multiple &lt;code&gt;goroutines&lt;/code&gt;&lt;/p&gt;&#10;&lt;p&gt;You can declare a channel and the type of content the channel will receive like below.&lt;/p&gt;&#10;&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;var myChannel chan int&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;p&gt;The &lt;code&gt;int&lt;/code&gt; above is the type of data it can receive and the data can be send using&lt;/p&gt;</description></item><item><title>GoLang: try-catch</title><link>https://samarthya.me/posts/golang-try-catch/</link><pubDate>Mon, 22 Feb 2021 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/golang-try-catch/</guid><description>&lt;p&gt;GoLang doesn’t have a try and catch like the popular C++ or Java languages, what it has is &lt;code&gt;panic-recover&lt;/code&gt;.&lt;/p&gt;&#10;&lt;p&gt;Non critical errors are returned as normal values and for the critical ones, &lt;code&gt;panic&lt;/code&gt; is used&lt;/p&gt;</description></item><item><title>GoLang: Hash</title><link>https://samarthya.me/posts/golang-hash/</link><pubDate>Mon, 01 Feb 2021 09:20:50 +0000</pubDate><guid>https://samarthya.me/posts/golang-hash/</guid><description>&lt;p&gt;Previously I talked about files, encoding in &lt;code&gt;golang&lt;/code&gt;. In this LTD (learn to do) I will talk about &lt;code&gt;hash&lt;/code&gt; package in general.&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://blog.samarthya.me/wps/2021/01/30/golang-encoding/" target="_blank" rel="noreferrer"&gt;https://blog.samarthya.me/wps/2021/01/30/golang-encoding/&lt;/a&gt;&lt;/p&gt;&#10;&#10;&lt;h2 class="relative group"&gt;Help&#10; &lt;div id="help" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#help" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/hash/#Hash" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/hash/#Hash&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/crypto/#Hash.New" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/crypto/#Hash.New&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/src/crypto/crypto.go?s=364:378#L6" target="_blank" rel="noreferrer"&gt;https://golang.org/src/crypto/crypto.go?s=364:378#L6&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/crypto/#pkg-subdirectories" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/crypto/#pkg-subdirectories&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; Package crypto collects common cryptographic constants.&#10;— Official golang documentation&#10;&lt;/div&gt;&#10;&#10;&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;const (&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; MD4 Hash = 1 + iota // import golang.org/x/crypto/md4&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; MD5 // import crypto/md5&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA1 // import crypto/sha1&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA224 // import crypto/sha256&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA256 // import crypto/sha256&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA384 // import crypto/sha512&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA512 // import crypto/sha512&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; MD5SHA1 // no implementation; MD5+SHA1 used for TLS RSA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; RIPEMD160 // import golang.org/x/crypto/ripemd160&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA3_224 // import golang.org/x/crypto/sha3&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA3_256 // import golang.org/x/crypto/sha3&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA3_384 // import golang.org/x/crypto/sha3&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA3_512 // import golang.org/x/crypto/sha3&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA512_224 // import crypto/sha512&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; SHA512_256 // import crypto/sha512&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; BLAKE2s_256 // import golang.org/x/crypto/blake2s&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; BLAKE2b_256 // import golang.org/x/crypto/blake2b&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; BLAKE2b_384 // import golang.org/x/crypto/blake2b&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; BLAKE2b_512 // import golang.org/x/crypto/blake2b&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;p&gt;Let&amp;rsquo;s try out a simple MD5 hasher.&lt;/p&gt;</description></item><item><title>GoLang: encoding</title><link>https://samarthya.me/posts/golang-encoding/</link><pubDate>Sat, 30 Jan 2021 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/golang-encoding/</guid><description>&lt;p&gt;Package encoding provide capabilities to convert data to and from byte-level and textual representations.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;encoding/gob&lt;/li&gt;&#10;&lt;li&gt;encoding/json, and&lt;/li&gt;&#10;&lt;li&gt;encoding/xml&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; The &lt;em&gt;gob&lt;/em&gt; is Go’s format for &lt;em&gt;serializing&lt;/em&gt; and &lt;em&gt;deserializing&lt;/em&gt;. The gob was tailored for communicating between two servers written in Go.&#10;&lt;/div&gt;&#10;&#10;&lt;ul&gt;&#10;&lt;li&gt;Only exported fields are encoded; zero values are not taken into account&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; Package gob manages streams of gobs – binary values exchanged between an Encoder (transmitter) and a Decoder (receiver).&#10;&lt;/div&gt;&#10;&#10;&#10;&lt;h2 class="relative group"&gt;Format GoB&#10; &lt;div id="format-gob" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#format-gob" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h2&gt;&#10;&lt;p&gt;Let’s create a simple Type &lt;code&gt;Blog&lt;/code&gt; and we will encode and decode it using the gob format.&lt;/p&gt;</description></item><item><title>GoLang: Hex Output</title><link>https://samarthya.me/posts/golang-hex-output/</link><pubDate>Fri, 29 Jan 2021 17:47:07 +0000</pubDate><guid>https://samarthya.me/posts/golang-hex-output/</guid><description>&lt;p&gt;In last few blogs I have written about reading &lt;code&gt;commandline&lt;/code&gt; parameters reading &lt;code&gt;files&lt;/code&gt; and using the &lt;code&gt;os&lt;/code&gt; package.&lt;/p&gt;&#10;&lt;p&gt;In this blog, I will combine some these items to read a file &lt;code&gt;byte&lt;/code&gt; by &lt;code&gt;byte&lt;/code&gt; using the &lt;code&gt;bufio&lt;/code&gt; package &lt;code&gt;func&lt;/code&gt;&amp;rsquo;s.&lt;/p&gt;</description></item><item><title>GoLang: Program Banner</title><link>https://samarthya.me/posts/golang-program-banner/</link><pubDate>Fri, 29 Jan 2021 07:39:04 +0000</pubDate><guid>https://samarthya.me/posts/golang-program-banner/</guid><description>&lt;p&gt;In the last &lt;a href="https://samarthya.me/posts/golang-command-line-arguments/" &gt;blog&lt;/a&gt; I talked about command line arguments &lt;code&gt;os.Args[]&lt;/code&gt;. In this I will try and create a sample banner program that shall&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Take 3 arguments&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;n&lt;/code&gt; - Number of times a message has to be repeated.&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;m&lt;/code&gt; - The message that needs to be shown.&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;d&lt;/code&gt; - If debug message needs to be shown.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;I am going to use the &lt;code&gt;flags&lt;/code&gt; package.&lt;/p&gt;</description></item><item><title>GoLang: Command line arguments</title><link>https://samarthya.me/posts/golang-command-line-arguments/</link><pubDate>Wed, 27 Jan 2021 17:06:11 +0000</pubDate><guid>https://samarthya.me/posts/golang-command-line-arguments/</guid><description>&lt;p&gt;Reading the golang official documentation is fun, today I saw the &lt;code&gt;Variables&lt;/code&gt; in package &lt;code&gt;os&lt;/code&gt;&lt;/p&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; var Args []&lt;a href="https://golang.org/pkg/builtin/#string" target="_blank" rel="noreferrer"&gt;string&lt;/a&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;p&gt;It allows you to hold command line arguments and a simple main program that can help you validate this.&lt;/p&gt;</description></item><item><title>Files: GoLang</title><link>https://samarthya.me/posts/files-golang-2/</link><pubDate>Mon, 25 Jan 2021 12:46:47 +0000</pubDate><guid>https://samarthya.me/posts/files-golang-2/</guid><description>&lt;p&gt;In the last blog, I tried &lt;a href="https://samarthya.me/posts/files-golang/" &gt;reading a file in GoLang&lt;/a&gt;.&lt;/p&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; My repository in GitHub has all the code that I write (&lt;a href="https://github.com/samarthya/valueandpointer" target="_blank" rel="noreferrer"&gt;link&lt;/a&gt;)&#10;&lt;/div&gt;&#10;&#10;&lt;p&gt;Now, I will extend the same program to write to the same file.&lt;/p&gt;</description></item><item><title>Files: GoLang</title><link>https://samarthya.me/posts/files-golang/</link><pubDate>Thu, 21 Jan 2021 17:26:56 +0000</pubDate><guid>https://samarthya.me/posts/files-golang/</guid><description>&lt;p&gt;Learning a new syntax and the libraries is always a task, and the only way forward is gradual. In this blog I will try to create a small program to read a text file and will keep updating the program to include more sophistication&lt;/p&gt;</description></item><item><title>GOLang: Reflection</title><link>https://samarthya.me/posts/golang-reflection/</link><pubDate>Sat, 16 Jan 2021 08:18:34 +0000</pubDate><guid>https://samarthya.me/posts/golang-reflection/</guid><description>&lt;h2 class="relative group"&gt;Must Read&#10; &lt;div id="must-read" class="anchor"&gt;&lt;/div&gt;&#10; &#10; &lt;span&#10; class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;&#10; &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#must-read" aria-label="Anchor"&gt;#&lt;/a&gt;&#10; &lt;/span&gt;&#10; &#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://blog.golang.org/laws-of-reflection" target="_blank" rel="noreferrer"&gt;https://blog.golang.org/laws-of-reflection&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/reflect/" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/reflect/&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/reflect/#Kind" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/reflect/#Kind&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://golang.org/pkg/reflect/#Value" target="_blank" rel="noreferrer"&gt;https://golang.org/pkg/reflect/#Value&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="lead text-neutral-500 dark:text-neutral-400 !mb-9 text-xl"&gt;&#10; Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types.&#10;&lt;/div&gt;&#10;&#10;&lt;p&gt;Reflection is a way to examine own structure. Let&amp;rsquo;s try and learn it via examples.&lt;/p&gt;</description></item><item><title>GOLang: Interfaces</title><link>https://samarthya.me/posts/golang-interfaces/</link><pubDate>Tue, 12 Jan 2021 09:26:04 +0000</pubDate><guid>https://samarthya.me/posts/golang-interfaces/</guid><description>&lt;p&gt;Interfaces are an interesting concept to learn in GOLANG. There are a tonne of informative articles and here is my contribution to it.&lt;/p&gt;&#10;&lt;p&gt;In classical Object Oriented everything is treated in parlance of &lt;code&gt;Object&lt;/code&gt; or &lt;code&gt;Class&lt;/code&gt; like in &lt;code&gt;Java&lt;/code&gt; or &lt;code&gt;C++&lt;/code&gt;. In Go there is no class or inheritance.&lt;/p&gt;</description></item></channel></rss>