<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shubham Chadokar</title>
    <description>The latest articles on DEV Community by Shubham Chadokar (@schadokar).</description>
    <link>https://dev.to/schadokar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F176746%2Fe7f93e6e-1ed9-41a6-bbaf-7668ad11cdb1.png</url>
      <title>DEV Community: Shubham Chadokar</title>
      <link>https://dev.to/schadokar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/schadokar"/>
    <language>en</language>
    <item>
      <title>The fastest way to concatenate strings in Golang</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Tue, 30 Apr 2024 16:43:36 +0000</pubDate>
      <link>https://dev.to/schadokar/the-fastest-way-to-concatenate-strings-in-golang-5mf</link>
      <guid>https://dev.to/schadokar/the-fastest-way-to-concatenate-strings-in-golang-5mf</guid>
      <description>&lt;p&gt;As a developer, we should be aware of all the available ways to implement a solution. This gives us the edge to implement a solution as per the needs.&lt;/p&gt;

&lt;p&gt;In this short tutorial, you will learn multiple ways to concatenate a string and which is the fastest.&lt;/p&gt;

&lt;p&gt;We will add benchmark testing, to analyse the performance of the function. The results may vary for you due to the machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Plus (+) Operator
&lt;/h2&gt;

&lt;p&gt;The plus operator is not only used for integers and float but it can be used to concatenate strings, provided the operants are of string type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main.go
package main

import "fmt"

func main() {
    fmt.Println(plusOperator())
}

func plusOperator() string {
    s1 := "practice"
    s2 := "go"

    return (s1 + s2)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benchmark Test
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main_test.go
package main

import "testing"

func BenchmarkPlusOperator(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        plusOperator()
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ go test -bench=.
goos: darwin
goarch: arm64
pkg: cb/practicegocode
BenchmarkPlusOperator-11     118339720            10.23 ns/op
PASS
ok  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Append (+=) Operator
&lt;/h2&gt;

&lt;p&gt;The append operator appends one string to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main.go
package main

func main {
...

func appendOperator() string {
    s1 := "practice"
    s2 := "go"

    s1 += s2
    return s2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benchmark Test
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main_test.go
package main

import "testing"

func BenchmarkAppendOperator(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        appendOperator()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ go test -bench=.
goos: darwin
goarch: arm64
pkg: cb/practicegocode
BenchmarkAppendOperator-11   64080028             17.60 ns/op
PASS
ok  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Sprintf function
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;fmt.Sprintf&lt;/code&gt; function is available in &lt;code&gt;fmt&lt;/code&gt; package. This should be only used when you have to format a string of different data types or in a certain format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main.go
package main

func main() {
...

func sprintf() string {
    s1 := "practice"
    s2 := "go"

    return fmt.Sprintf("%s%s", s1, s2)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benchmark Test
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main_test.go
package main

import "testing"

func BenchmarkSprintfOperator(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        sprintf()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ go test -bench=.
goos: darwin
goarch: arm64
pkg: cb/practicegocode
BenchmarkSprintfOperator-11     16939860          70.79 ns/op
PASS
ok  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using strings.Builder
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;strings.Builder&lt;/code&gt; method appends the bytes of &lt;code&gt;s1&lt;/code&gt; and &lt;code&gt;s2&lt;/code&gt; strings to the &lt;code&gt;str&lt;/code&gt; bytes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main.go
package main

func main() {
...

func stringBuilder() string {
    s1 := "practice"
    s2 := "go"

    var str strings.Builder
    str.WriteString(s1)
    str.WriteString(s2)

    return str.String()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benchmark Test
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// file: main_test.go
package main

import "testing"

func BenchmarkStringsBuilderOperator(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        stringsBuilder()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ go test -bench=.
goos: darwin
goarch: arm64
pkg: cb/practicegocode
BenchmarkStringsBuilderOperator-11   42873091    26.40 ns/op
PASS
ok  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Test
&lt;/h2&gt;

&lt;p&gt;Lets run all the benchmark tests together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BenchmarkPlusOperator-11                115559880 10.13 ns/op
BenchmarkAppendOperator-11              62112871  17.74 ns/op
BenchmarkSprintfOperator-11             16762341  72.46 ns/op
BenchmarkStringsBuilderOperator-11      45078675  26.17 ns/op
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;+&lt;/code&gt; operator is the fastest way to concatenate strings and &lt;code&gt;fmt.Sprintf&lt;/code&gt; is the slowest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;----------------Fastest--------------------
  +  &amp;gt;  +=  &amp;gt;  strings.Builder  &amp;gt;  fmt.Sprintf
  ----------------Slowest--------------------&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;You can also watch this tutorial&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/u2VnLNq8qDw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can connect with me at:&lt;br&gt;
&lt;a href="https://dev.to/schadokar"&gt;Dev.to&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/@practicego"&gt;YouTube Channel&lt;/a&gt;&lt;br&gt;
&lt;a href="https://schadokar.dev"&gt;Personal Blog&lt;/a&gt;&lt;br&gt;
&lt;a href="https://linkedin.com/in/schadokar"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://twitter.com/schadokar1"&gt;Twitter&lt;/a&gt;&lt;/p&gt;




</description>
      <category>go</category>
      <category>webdev</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Read and Write files in Golang</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Sat, 27 Apr 2024 17:01:48 +0000</pubDate>
      <link>https://dev.to/schadokar/read-and-write-files-in-golang-2b75</link>
      <guid>https://dev.to/schadokar/read-and-write-files-in-golang-2b75</guid>
      <description>&lt;p&gt;In this tutorial, we will learn how to read, write, and append to a file using Golang.&lt;/p&gt;

&lt;p&gt;The built-in &lt;code&gt;os&lt;/code&gt; package provides reading and writing files. Earlier it used to be handled by &lt;code&gt;io/ioutil&lt;/code&gt; package. &lt;/p&gt;

&lt;p&gt;A file must have correct file permissions to perform respective operations.&lt;/p&gt;

&lt;p&gt;Following are the file modes(permissions) codes that we will need in the tutorial.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

0000     no permissions
0700     read, write, &amp;amp; execute only for the owner
0770     read, write, &amp;amp; execute for owner and group
0777     read, write, &amp;amp; execute for owner, group and others
0111     execute
0222     write
0333     write &amp;amp; execute
0444     read
0555     read &amp;amp; execute
0666     read &amp;amp; write
0740     owner can read, write, &amp;amp; execute; group can only read; others have no permissions


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can also watch this tutorial on YouTube.&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://www.youtube.com/watch?si=Om4wal2ngJ4x9hzs&amp;amp;v=lkeh0TRSBfo&amp;amp;feature=youtu.be" rel="noopener noreferrer"&gt;
      youtube.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  Write file in golang
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;os.Writefile&lt;/code&gt; function accepts the filename or full path with extension if any, data or content in &lt;code&gt;[]byte&lt;/code&gt; format and file permission code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

func WriteFile(name string, data []byte, perm os.FileMode) error


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The below code will create a new file if it doesn't exist and write or it will override with new content to the existing file. &lt;br&gt;
The &lt;code&gt;0777&lt;/code&gt; file mode gives read, write and execution permission.&lt;br&gt;
The &lt;code&gt;data&lt;/code&gt; is a string converted to &lt;code&gt;[]byte&lt;/code&gt; format.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"dev.to"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"test.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0777&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"file written successfully."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Read file in golang
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;os.ReadFile&lt;/code&gt; function accepts the filename or full file path and returns &lt;code&gt;[]byte&lt;/code&gt; and error.&lt;/p&gt;

&lt;p&gt;It will throw an error if the file doesn't exist or the file doesn't have permission to read.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

func ReadFile(name string) ([]byte, error)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    data, err := os.ReadFile("test.txt")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(string(data))
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Append to an existing file
&lt;/h2&gt;

&lt;p&gt;There are 2 ways you can append content to an existing file.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Read and Write
&lt;/h3&gt;

&lt;p&gt;In this approach, first read the file, append the content and then write the file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    data, err := os.ReadFile("test.txt")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(string(data))

    msg := []byte("\nappended message")

    data = append(data, msg...)

    err = os.WriteFile("test.txt", data, 0777)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("file written successfully.")
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  2. Open and write
&lt;/h3&gt;

&lt;p&gt;In this approach, first, open the file with the &lt;code&gt;O_APPEND&lt;/code&gt; flag then write the content and close the file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    file, err := os.OpenFile("test.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0777)
    if err != nil {
        log.Fatal(err)
    }

    defer file.Close()

    msg := []byte("\n another appended message")
    _, err = file.Write(msg)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("file appended successfully.")
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;os.O_APPEND&lt;/code&gt; - File permission append&lt;br&gt;
&lt;code&gt;os.O_CREATE&lt;/code&gt; - Create a new file if it doesn't exist&lt;br&gt;
&lt;code&gt;os.O_WRONLY&lt;/code&gt; - Write only&lt;/p&gt;



&lt;p&gt;I hope you like this tutorial. &lt;br&gt;
Happy Coding. Please Follow and Subscribe to YouTube.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wJ6JP22YOUk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>go</category>
      <category>file</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Best tool to write a technical ebook</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Fri, 05 Jun 2020 06:06:53 +0000</pubDate>
      <link>https://dev.to/schadokar/best-tool-to-write-a-technical-ebook-59kd</link>
      <guid>https://dev.to/schadokar/best-tool-to-write-a-technical-ebook-59kd</guid>
      <description>&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@retrosupply?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;RetroSupply&lt;/a&gt; on &lt;a href="https://unsplash.com/images/things/typewriter?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are best tools or editor available to write a technical eBook?&lt;br&gt;
I recently wrote a tech eBook and struggled a lot to find a good editor. In the end, I used the VS Code with some markdown plugin. I wrote the eBook in md format. The result was good but when I was converting it to PDF or ePub format it was bad. Then I used Typora to convert it to PDF format, the result is good compared to VS Code plugin. But it is good only for PDF. &lt;a href="https://schadokar.dev/ebooks/playtime-with-hyperledger-composer/"&gt;Check here&lt;/a&gt;.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This question is basically focused for Windows and Linux user.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I am using Pandoc. I am struggling to converting it to epub or other format with proper formatting. Which tool or editor should i use to do this?&lt;br&gt;&lt;br&gt;
For the Mac OS Bear is a great editor.  &lt;/p&gt;

&lt;p&gt;Is there any other format than markdown, in which code writing is easy as in md?&lt;/p&gt;

&lt;p&gt;Please give your suggestions on this.&lt;br&gt;&lt;br&gt;
Please include your approach, what tools you would use to write a tech ebook. 😃&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>writing</category>
      <category>help</category>
    </item>
    <item>
      <title>My First eBook</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Mon, 01 Jun 2020 05:27:52 +0000</pubDate>
      <link>https://dev.to/schadokar/my-first-ebook-k16</link>
      <guid>https://dev.to/schadokar/my-first-ebook-k16</guid>
      <description>&lt;p&gt;Hello Everyone,&lt;/p&gt;

&lt;p&gt;I like to share, during this covid19 pandemic, I wrote my first eBook 📘. The journey to write the book was awesome. I learned a lot from this like what should be the approach, order of content etc.&lt;br&gt;&lt;br&gt;
I am in the middle of writing the complete article on how I wrote an eBook. I'll include all the tools and approaches I used and yes as it was my first attempt so lots of dos n don'ts 😉.&lt;/p&gt;

&lt;p&gt;For now, please have a look on it. It's topic is &lt;a href="https://schadokar.dev/ebooks/playtime-with-hyperledger-composer/"&gt;Playtime with Hyperledger Composer&lt;/a&gt;. It is free and available in PDF format. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvg3bdsvll6og7v1ew3qb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvg3bdsvll6og7v1ew3qb.png" alt="Playtime with Hyperledger Composer" width="800" height="1276"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://schadokar.dev/ebooks/playtime-with-hyperledger-composer/"&gt;Link to eBook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is unfortunate that it deprecated but I still believe, it is a great tool for students to build a project on Blockchain.&lt;/p&gt;

&lt;p&gt;I would love to hear your valuable feedback.&lt;/p&gt;

&lt;p&gt;Thanks for your time.&lt;/p&gt;

&lt;p&gt;Shubham Chadokar&lt;br&gt;
&lt;a href="https://schadokar.dev"&gt;schadokar.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>writing</category>
      <category>blockchain</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Convert String to Int and Int to String in Golang</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Sat, 28 Mar 2020 07:11:01 +0000</pubDate>
      <link>https://dev.to/schadokar/convert-string-to-int-and-int-to-string-in-golang-dmb</link>
      <guid>https://dev.to/schadokar/convert-string-to-int-and-int-to-string-in-golang-dmb</guid>
      <description>&lt;p&gt;Golang standard library has provided 2 functions &lt;a href="https://golang.org/pkg/strconv/#Atoi"&gt;Atoi&lt;/a&gt; and &lt;a href="https://golang.org/pkg/strconv/#Itoa"&gt;Itoa&lt;/a&gt; to convert string to int and int to string respectively.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://schadokar.dev/to-the-point/convert-string-to-int-and-int-to-string-in-golang/"&gt;schadokar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These 2 functions placed inside the &lt;a href="https://golang.org/pkg/strconv/"&gt;strconv&lt;/a&gt; package.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Package strconv implements conversions to and from string representations of basic data types.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  String to Int
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;strconv.Atoi&lt;/code&gt; function takes a string and returns an int and an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Atoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will return type &lt;code&gt;int&lt;/code&gt; and type &lt;code&gt;int&lt;/code&gt; is system dependent. It is 32 bits on the 32-bit system and 64 bits on the 64-bit system.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Use the term ASCII to Int to remember the func name.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"strconv"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"1234"&lt;/span&gt;

    &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;strconv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Atoi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type: %T, Value: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// convert int to int64&lt;/span&gt;
    &lt;span class="n"&gt;i64&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type: %T, Value: %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type: int, Value: 1234
Type: int64, Value: 1234
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Int to String
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;strconv.Itoa&lt;/code&gt; takes &lt;code&gt;int&lt;/code&gt; as an argument and returns the &lt;code&gt;string&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Itoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"strconv"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;322020&lt;/span&gt;

    &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;strconv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Itoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type: %T, Value: %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type: string, Value: 322020
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building an offline To-Do App with React</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Wed, 04 Mar 2020 04:25:47 +0000</pubDate>
      <link>https://dev.to/schadokar/building-an-offline-to-do-app-with-react-3m8e</link>
      <guid>https://dev.to/schadokar/building-an-offline-to-do-app-with-react-3m8e</guid>
      <description>&lt;p&gt;In this tutorial, we will create a to-do list app in reactjs. We will use browser local storage to save the tasks, which will keep the tasks even after we close the browser. In the end, we will host this application on Github pages. &lt;/p&gt;

&lt;p&gt;The complete tutorial is originally published on &lt;a href="https://codesource.io/building-an-offline-to-do-app-with-react/"&gt;codesource.io&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>github</category>
    </item>
    <item>
      <title>How to use Swapper in Golang?</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Tue, 03 Mar 2020 14:41:31 +0000</pubDate>
      <link>https://dev.to/schadokar/how-to-use-swapper-in-golang-1h35</link>
      <guid>https://dev.to/schadokar/how-to-use-swapper-in-golang-1h35</guid>
      <description>&lt;p&gt;&lt;a href="https://golang.org/pkg/reflect/#Swapper"&gt;Swapper&lt;/a&gt; is a function defined in the &lt;a href="https://golang.org/pkg/reflect/"&gt;reflect&lt;/a&gt; package. This function takes a slice and returns a swap function. This swap function takes 2 indexes as arguments and swaps the values at index position in the slice. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://schadokar.dev/to-the-point/swapper-in-golang/"&gt;schadokar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Function Definition
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Swapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's try&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"reflect"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Before swap: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;swapF&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;reflect&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Swapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;swapF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After 1 swap: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;swapF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After 2 swap: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://play.golang.org/p/pljUgJ0mEnJ"&gt;Try it&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before swap: [1 2 3]
After 1 swap: [2 1 3]
After 2 swap: [3 1 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Swapper panics if the provided interface is not a slice.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;panic: reflect: call of Swapper on &amp;lt;Type&amp;gt; Value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reverse a slice using Swapper
&lt;/h3&gt;

&lt;p&gt;Swap first element with last element, the second element with second last and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"reflect"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Before swap: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;swapF&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;reflect&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Swapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;swapF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After swap: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://play.golang.org/p/yFtphVvgvBN"&gt;Try it&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before swap: [1 2 3 4 5 6 7]
After swap: [7 6 5 4 3 2 1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use Swapper in Bubble sort
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"reflect"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Before swapper: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;swapF&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;reflect&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Swapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;swapF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After swapper: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before swapper: [1 2 6 3 8 0 7 9 5 4]
After swapper: [0 1 2 3 4 5 6 7 8 9]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>go</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Build a CRUD application in Golang with PostgreSQL</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Mon, 02 Mar 2020 10:55:24 +0000</pubDate>
      <link>https://dev.to/schadokar/build-a-crud-application-in-golang-with-postgresql-4lob</link>
      <guid>https://dev.to/schadokar/build-a-crud-application-in-golang-with-postgresql-4lob</guid>
      <description>&lt;p&gt;The tutorial is published on &lt;a href="https://codesource.io/build-a-crud-application-in-golang-with-postgresql/"&gt;codesource.io&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>postgres</category>
      <category>crud</category>
    </item>
    <item>
      <title>How to join multiple strings in golang?</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Fri, 28 Feb 2020 04:35:55 +0000</pubDate>
      <link>https://dev.to/schadokar/how-to-join-multiple-strings-in-golang-3p11</link>
      <guid>https://dev.to/schadokar/how-to-join-multiple-strings-in-golang-3p11</guid>
      <description>&lt;p&gt;There are multiple ways to join or concat strings in the golang. &lt;/p&gt;

&lt;p&gt;Let's start with the easy one.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published at &lt;a href="https://schadokar.dev"&gt;https://schadokar.dev&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Using the + operator 🔧
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

func main() {
    str1 := "Hello"
    // there is a space before World
    str2 := " World!"

    fmt.Println(str1 + str2)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using Sprint, Sprintf, Sprintln 🛠
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://golang.org/pkg/fmt/"&gt;fmt&lt;/a&gt; package has &lt;a href="https://golang.org/pkg/fmt/#Sprint"&gt;Sprint&lt;/a&gt;, &lt;a href="https://golang.org/pkg/fmt/#Sprintf"&gt;Sprintf&lt;/a&gt; and &lt;a href="https://golang.org/pkg/fmt/#Sprintln"&gt;Sprintln&lt;/a&gt; function which can format the strings using the default or custom formats.&lt;/p&gt;

&lt;p&gt;All the &lt;code&gt;Sprint&lt;/code&gt; function are variadic functions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://medium.com/rungo/variadic-function-in-go-5d9b23f4c01a"&gt;Variadic functions&lt;/a&gt; can be called with any number of trailing arguments. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Sprint
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Sprint&lt;/code&gt; formats using the default formats and returns the resulting string. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Sprint&lt;/code&gt; accepts an empty interface. It means it can take n elements of any type.&lt;br&gt;&lt;br&gt;
If no element of type string is passed then the resulting string will add a Space between the elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

func main() {
    num := 26

    str := "Feb"

    boolean := true

    withStr := fmt.Sprint(num, str, boolean)

    fmt.Println("With string: ", withStr)

    withOutStr := fmt.Sprint(num, boolean)

    fmt.Println("Without string: ", withOutStr)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;With string:  26Febtrue
Without string:  26 true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sprintf
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Sprintf&lt;/code&gt; formats according to a format specifier and returns the resulting string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Format Specifiers&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%v  the value in a default format
%s  the uninterpreted bytes of the string or slice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check all the &lt;a href="https://golang.org/pkg/fmt/#hdr-Printing"&gt;available format specifier&lt;/a&gt; in the &lt;code&gt;fmt&lt;/code&gt; package.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can use the &lt;code&gt;Sprintf&lt;/code&gt; function to create the &lt;code&gt;connection string&lt;/code&gt; of the DB.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example we will create a &lt;strong&gt;&lt;em&gt;Postgres Connection URL&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Connection URL format: &lt;strong&gt;postgres://username:password@hostname/databasename&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

func main() {

    dbname := "testdb"

    username := "admin"

    password := "test1234"

    hostname := "localhost"

    connectionURL := fmt.Sprintf("postgres://%s:%s@%v/%v", username, password, hostname, dbname)

    fmt.Println(connectionURL)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres://admin:test1234@localhost/testdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sprintln
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Sprintln&lt;/code&gt; formats the elements or arguments using the default formats. Spaces are added between the elements and a new line is added in the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

func main() {

    str1 := "Hello"
    str2 := "Gophers!"

    msg := fmt.Sprintln(str1, str2)

    fmt.Println(msg)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Gophers!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using the Join function  🔩
&lt;/h2&gt;

&lt;p&gt;The golang standard library has provided a  &lt;a href="https://golang.org/pkg/strings/#Join"&gt;Join&lt;/a&gt; function in the &lt;a href="https://golang.org/pkg/strings/"&gt;strings&lt;/a&gt; package. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Join&lt;/code&gt; function takes an array of strings and a separator to join them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Join(elems []string, sep string) string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example has an array of weekdays. The &lt;code&gt;Join&lt;/code&gt; function will return a string of weekdays separated by &lt;code&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Using &lt;code&gt;Join&lt;/code&gt; you can convert an array of string to a string.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "strings"
)

func main() {
    weekdays := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}
    // there is a space after comma
    fmt.Println(strings.Join(weekdays, ", "))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Monday, Tuesday, Wednesday, Thursday, Friday
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>go</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Store Hyperledger Fabric certificates and keys in CouchDB</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Sun, 09 Feb 2020 07:05:17 +0000</pubDate>
      <link>https://dev.to/schadokar/store-hyperledger-fabric-certificates-and-keys-in-couchdb-4oo0</link>
      <guid>https://dev.to/schadokar/store-hyperledger-fabric-certificates-and-keys-in-couchdb-4oo0</guid>
      <description>&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@mr_williams_photography?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Micah Williams&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/safe?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hyperledger Fabric is all about permissions. These permissions are provided in the form of certificates and keys. In broad term, it is known as &lt;a href="https://hyperledger-fabric.readthedocs.io/en/latest/identity/identity.html"&gt;Identities&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Originally published at &lt;a href="https://schadokar.dev/posts/store-hyperledger-fabric-certificates-and-keys-in-couchdb/"&gt;https://schadokar.dev&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When an application interacts with the Hyperledger Fabric Network, it uses this identity to authenticate itself. Fabric network validates the identity and authorizes the application to interact.&lt;/p&gt;

&lt;p&gt;In short, identities are very important and if you don't save them properly, then it may turn into a headache. 😩&lt;/p&gt;

&lt;h2&gt;
  
  
  Where can I store the Identities? 💼
&lt;/h2&gt;

&lt;p&gt;In Hyperledger Fabric, this storage is known as &lt;a href="https://hyperledger-fabric.readthedocs.io/en/latest/developapps/wallet.html"&gt;&lt;strong&gt;&lt;em&gt;Wallet&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are three types of wallet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;File System&lt;/em&gt;&lt;/strong&gt;:  This is a simple folder. A local storage wallet. It is a good default choice for wallets. In &lt;code&gt;fabric-samples/balance-transfer&lt;/code&gt;, the &lt;code&gt;file system&lt;/code&gt; is the default wallet. When you run the &lt;code&gt;balance-transfer&lt;/code&gt; it creates a &lt;code&gt;fabric-client-kv-orgName&lt;/code&gt; folder and saves all the identities in it. This configuration is defined in the &lt;code&gt;orgname.yaml&lt;/code&gt; &lt;a href="https://github.com/hyperledger/fabric-samples/blob/release-1.4/balance-transfer/artifacts/org1.yaml"&gt;link&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;In-Memory&lt;/em&gt;&lt;/strong&gt;:
A wallet in application storage. Use this type of wallet when your application is running in a constrained environment without access to a file system; typically a web browser. It’s worth remembering that this type of wallet is volatile; identities will be lost after the application ends normally or crashes. - &lt;a href="https://hyperledger-fabric.readthedocs.io/en/latest/developapps/wallet.html#types"&gt;Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;CouchDB&lt;/em&gt;&lt;/strong&gt;:
Using couchdb as a wallet. This option is best for production.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In this tutorial, we will configure the &lt;code&gt;CouchDB&lt;/code&gt; as the Wallet. 👨🏻‍💻&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;For the demonstration, I am using &lt;code&gt;Fabric Node SDK&lt;/code&gt; and &lt;code&gt;fabric/samples/balance-transfer&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The wallet uses 2 stores to save the certificates and keys:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. State Store:
&lt;/h4&gt;

&lt;p&gt;The state store is used to store the certificates of the enrolled identity. It stores the basic information of the identity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mspid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"org1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"roles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"affiliation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enrollmentSecret"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;ENROLLMENT_SECRET&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enrollment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"signingIdentity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;PRIVATE_KEY_NAME&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"identity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"certificate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;SIGN_CERT&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;❗️ &lt;em&gt;Note: The signingIdentity is the pointer or the address of the private and public key stored in the crypto-store.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  2. Crypto Store:
&lt;/h4&gt;

&lt;p&gt;The crypto store is used to store the public and private key of the identity.&lt;/p&gt;



&lt;p&gt;To configure the couchdb as wallet:&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;Import the &lt;code&gt;CouchDBKeyValueStore&lt;/code&gt; library, which is provided by the &lt;code&gt;Node SDK&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CDBKVS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fabric-client/lib/impl/CouchDBKeyValueStore.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Do read the &lt;a href="https://github.com/hyperledger/fabric-sdk-node/blob/release-1.4/fabric-client/lib/impl/CouchDBKeyValueStore.js"&gt;&lt;code&gt;CouchDBKeyValueStore.js&lt;/code&gt;&lt;/a&gt; it is worth reading.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;Set the &lt;code&gt;state store&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;stateStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CDBKVS&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://&amp;lt;USERNAME&amp;gt;:&amp;lt;PASSWORD&amp;gt;@&amp;lt;URL&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;DB_NAME&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fabric-client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loadFromConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;path of network.yaml&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStateStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stateStore&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;USERNAME&amp;gt;&lt;/code&gt; is the username of the couchdb.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;PASSWORD&amp;gt;&lt;/code&gt; is the password of the couchdb.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;URL&amp;gt;&lt;/code&gt; is the couchdb URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;DB_NAME&amp;gt;&lt;/code&gt; (OPTIONAL) is the dbname to use as state store. The default dbname is &lt;code&gt;userdb&lt;/code&gt;. It creates the DB if it doesn't exist.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://hyperledger.github.io/fabric-sdk-node/release-1.4/Client.html"&gt;Client&lt;/a&gt; is the interface between the user and the fabric network.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;Set the &lt;code&gt;crypto store&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cryptoSuite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newCryptoSuite&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cryptoKS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newCryptoKeyStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CDBKVS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://&amp;lt;USERNAME&amp;gt;:&amp;lt;PASSWORD&amp;gt;@&amp;lt;URL&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;DB_NAME&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;cryptoSuite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCryptoKeyStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cryptoKS&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCryptoSuite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cryptoSuite&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You have to update the client according to the above steps to make it use the couchdb.&lt;br&gt;&lt;br&gt;
In the next section, we'll implement the above steps in the &lt;code&gt;balance-transfer&lt;/code&gt; fabric sample.&lt;/p&gt;


&lt;h2&gt;
  
  
  Implementation of CouchDB in Balance Transfer
&lt;/h2&gt;

&lt;p&gt;I am using the &lt;a href="https://github.com/hyperledger/fabric-samples/blob/release-1.4/balance-transfer"&gt;balance transfer&lt;/a&gt; fabric sample as a reference.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I am assuming that you know how to run the balance transfer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Start the balance transfer network
&lt;/h3&gt;

&lt;p&gt;Follow the balance transfer instructions to start the network.&lt;/p&gt;

&lt;p&gt;It will start the network with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2 CAs&lt;/li&gt;
&lt;li&gt;A SOLO Orderer&lt;/li&gt;
&lt;li&gt;4 peers (2 peers per Org)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Start a couchdb for the wallet
&lt;/h3&gt;

&lt;p&gt;This step is optional if you're using the cloud based couchdb.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker-based Couchdb&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name couch-userdb -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password -p 5984:5984 -d couchdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Above command will pull the docker image of the &lt;code&gt;couchdb&lt;/code&gt; from the docker hub if it doesn't exist.&lt;/p&gt;
&lt;h5&gt;
  
  
  CouchDB Details:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Container Name: couch-userdb&lt;/li&gt;
&lt;li&gt;CouchDB Username: admin&lt;/li&gt;
&lt;li&gt;CouchDB Password: password&lt;/li&gt;
&lt;li&gt;URL: localhost:5984&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The CouchDB connection URL is&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://&amp;lt;USERNAME&amp;gt;:&amp;lt;PASSWORD&amp;gt;@&amp;lt;URL&amp;gt;

https://admin:password@localhost:5984
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Update the client in the balance-transfer
&lt;/h3&gt;

&lt;p&gt;Open the &lt;code&gt;app/helper.js&lt;/code&gt; and update the &lt;code&gt;getClientForOrg&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the below code, we just replaced &lt;code&gt;await client.initCredentialStores();&lt;/code&gt; with the above couchdb config steps.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;The changes we made,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Line 13:&lt;/em&gt;&lt;/strong&gt; Import the &lt;code&gt;CouchDBKeyValueStore&lt;/code&gt;. Step 1 from above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Line 31-52:&lt;/em&gt;&lt;/strong&gt; Set the state store and crypto store. Step 2 &amp;amp; 3.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a minor change in the above code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Client variable is used as hfc&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;hfc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fabric-client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Instead of Client&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fabric-client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;It is not necessary that db(dbname) of state store and crypto store is the same. Both the stores can have their separate dbs. It depends on the requirement. You can have state store and crypto store db as &lt;code&gt;orgName-state-store&lt;/code&gt; and &lt;code&gt;orgName-crypto-store&lt;/code&gt; respectively.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Each organization must have their state-store and crypto-store db, else it will throw the Authentication Error.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: fabric-ca request register failed with errors [[{"code":20,"message":"Authentication failure"}]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Register a new user in the balance transfer
&lt;/h3&gt;

&lt;p&gt;Once you register a user, you can check the state-store and crypto-store using the couchdb apis.&lt;/p&gt;

&lt;h5&gt;
  
  
  For Example: Register a user
&lt;/h5&gt;

&lt;p&gt;I used the below arguments to register a user. For &lt;code&gt;org1&lt;/code&gt;, I used the same db &lt;code&gt;org1db&lt;/code&gt; for both &lt;code&gt;state-store&lt;/code&gt; and &lt;code&gt;crypto-store&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name: alice&lt;/li&gt;
&lt;li&gt;Org: org1&lt;/li&gt;
&lt;li&gt;DBNAME: org1db&lt;/li&gt;
&lt;li&gt;CouchDB URL: &lt;a href="http://admin:password@localhost:5369"&gt;http://admin:password@localhost:5369&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open the browser, go to &lt;code&gt;http://localhost:5369/org1db/_all_docs&lt;/code&gt;. It returns all the docs saved in the &lt;code&gt;org1db&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa42idnp673kzemesehhs.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fa42idnp673kzemesehhs.PNG" alt="Alt Text" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The indexes &lt;code&gt;0, 1, 2&lt;/code&gt; are the certificates of the &lt;code&gt;admin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The index &lt;code&gt;3&lt;/code&gt; is the &lt;code&gt;alice&lt;/code&gt; certificate stored in the &lt;code&gt;state-store&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
The indexes &lt;code&gt;4-5&lt;/code&gt; are the &lt;code&gt;alice&lt;/code&gt;'s public and private keys stored in the &lt;code&gt;crypto-store&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;http://localhost:5369/org1db/alice&lt;/code&gt;.&lt;br&gt;
It returns all the details of the &lt;code&gt;alice&lt;/code&gt; stored in the state store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F296eeoxtef2yrvk55kv7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F296eeoxtef2yrvk55kv7.PNG" alt="Alt Text" width="800" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check the &lt;code&gt;signingIdentity&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"signingIdentity":"d37a97a8c2377c21537801ec1a929d81905ae57963a2f6c8ba0308931a7fc791"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, check the id of the indexes &lt;code&gt;4 &amp;amp; 5&lt;/code&gt; in the above image. Both are same.&lt;/p&gt;

&lt;p&gt;If you remember, &lt;code&gt;signingIdentity&lt;/code&gt; field is a reference of the private and public keys of the identity stored in the crypto store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;CouchDB wallet is a great choice for a production use case. You can try with other dbs but in that case, you have to write the library accordingly like &lt;code&gt;CouchDBKeyValueStore.js&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;Below are the references I found helpful.&lt;br&gt;&lt;br&gt;
If you find any resource which you think can be added here, don't feel shy to share. 😉&lt;/p&gt;




&lt;h2&gt;
  
  
  References 📌
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.ibm.com/tutorials/store-fabric-certificates-keys-ibm-cloudant-fabric-node-sdk/"&gt;https://developer.ibm.com/tutorials/store-fabric-certificates-keys-ibm-cloudant-fabric-node-sdk/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/53639061/hyperledger-fabric-what-is-the-difference-between-state-store-and-crypto-store"&gt;https://stackoverflow.com/questions/53639061/hyperledger-fabric-what-is-the-difference-between-state-store-and-crypto-store&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/54305378/hyperledger-fabric-client-credential-store-using-couchdb"&gt;https://stackoverflow.com/questions/54305378/hyperledger-fabric-client-credential-store-using-couchdb&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/58371858/hyperledger-fabric-client-credential-store-using-couchdbcouchdbkeyvaluestore"&gt;https://stackoverflow.com/questions/58371858/hyperledger-fabric-client-credential-store-using-couchdbcouchdbkeyvaluestore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>blockchain</category>
      <category>couchdb</category>
      <category>hyperledgerfabric</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Use Environment Variable in your next Golang Project</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Thu, 16 Jan 2020 14:23:47 +0000</pubDate>
      <link>https://dev.to/schadokar/use-environment-variable-in-your-next-golang-project-2o6c</link>
      <guid>https://dev.to/schadokar/use-environment-variable-in-your-next-golang-project-2o6c</guid>
      <description>&lt;p&gt;When it comes to creating a production-grade application, using the environment variable in the application is &lt;em&gt;de facto&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This post was originally posted on my personal blog 🖊️ &lt;a href="https://schadokar.dev/posts/go-env-ways/"&gt;schadokar.dev&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why should we use the environment variable?
&lt;/h2&gt;

&lt;p&gt;Suppose you have an application with many features and each feature need to access the Database. You configured all the DB information like &lt;code&gt;DBURL&lt;/code&gt;, &lt;code&gt;DBNAME&lt;/code&gt;, &lt;code&gt;USERNAME&lt;/code&gt; and &lt;code&gt;PASSWORD&lt;/code&gt; in each feature.&lt;/p&gt;

&lt;p&gt;There are a few major disadvantages to this approach, there can be many.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;h4&gt;
  
  
  Security Issue:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You're entering all the information in the code. Now, all the unauthorized person also have access to the DB. &lt;/li&gt;
&lt;li&gt;If you're using code versioning tool like &lt;code&gt;git&lt;/code&gt; then the details of your DB will go public once you push the code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;h4&gt;
  
  
  Code Management:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you are changing a single variable then you have to change in all the features. There is a high possibility that you'll miss one or two. 😌 been there&lt;/li&gt;
&lt;li&gt;You can categorize the environment variables like &lt;code&gt;PROD&lt;/code&gt;, &lt;code&gt;DEV&lt;/code&gt;, or &lt;code&gt;TEST&lt;/code&gt;. Just prefix the variable with the environment. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the start, it might look like some extra work, but this will reward you a lot in your project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ Just don't forget to include your environment files in the &lt;code&gt;.gitignore&lt;/code&gt;.⚠️&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;It is time for some action. 🔨&lt;/p&gt;

&lt;h3&gt;
  
  
  What are we going to do in this tutorial?
&lt;/h3&gt;

&lt;p&gt;In this tutorial, we will access environment variables in 3 different ways.&lt;/p&gt;

&lt;p&gt;You can use according to your requirement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;os&lt;/code&gt; package&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;godotenv&lt;/code&gt; package&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;viper&lt;/code&gt; package&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a Project
&lt;/h2&gt;

&lt;p&gt;Create a project &lt;code&gt;go-env-ways&lt;/code&gt; outside the &lt;code&gt;$GOPATH&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize the module
&lt;/h3&gt;

&lt;p&gt;Open the terminal inside the project root directory, and run the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;mod&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt; &lt;span class="k"&gt;go&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ways&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This module will keep a record of all the packages and their version used in the project. It is similar to &lt;code&gt;package.json&lt;/code&gt; in &lt;code&gt;nodejs&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;Let's start with the easiest one, using &lt;code&gt;os&lt;/code&gt; package.&lt;/p&gt;

&lt;h2&gt;
  
  
  os Package
&lt;/h2&gt;

&lt;p&gt;Golang provides &lt;code&gt;os&lt;/code&gt; package, an easy way to configure and access the environment variable.&lt;/p&gt;

&lt;p&gt;To set the environment variable,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Setenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get the environment variable,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a new file &lt;code&gt;main.go&lt;/code&gt; inside the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s"&gt;"fmt"&lt;/span&gt;
  &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// use os package to get the env variable which is already set&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;envVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;// set env variable using os package&lt;/span&gt;
  &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Setenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"gopher"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c"&gt;// return the env variable using os package&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// os package&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;envVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"os package: %s = %s &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the below command to check.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;span class="c"&gt;// Output&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="k"&gt;package&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gopher&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  GoDotEnv Package
&lt;/h2&gt;

&lt;p&gt;The easiest way to load the &lt;code&gt;.env&lt;/code&gt; file is using &lt;code&gt;godotenv&lt;/code&gt; package.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install
&lt;/h3&gt;

&lt;p&gt;Open the terminal in the project root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;joho&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;godotenv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Load the .env file in the current directory&lt;/span&gt;
&lt;span class="n"&gt;godotenv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c"&gt;// or&lt;/span&gt;

&lt;span class="n"&gt;godotenv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;".env"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Load method can load multiple env files at once. This also supports &lt;code&gt;yaml&lt;/code&gt;. For more information check out the &lt;a href="https://github.com/joho/godotenv"&gt;documentation&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a new &lt;code&gt;.env&lt;/code&gt; file in the project root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;STRONGEST_AVENGER&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="err"&gt;Thor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the &lt;code&gt;main.go&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="c"&gt;// Import godotenv&lt;/span&gt;
  &lt;span class="s"&gt;"github.com/joho/godotenv"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c"&gt;// use godot package to load/read the .env file and&lt;/span&gt;
&lt;span class="c"&gt;// return the value of the key&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;goDotEnvVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;// load .env file&lt;/span&gt;
  &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;godotenv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;".env"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error loading .env file"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// os package&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt; 

  &lt;span class="c"&gt;// godotenv package&lt;/span&gt;
  &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;goDotEnvVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"STRONGEST_AVENGER"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"godotenv : %s = %s &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"STRONGEST_AVENGER"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the terminal and run the &lt;code&gt;main.go&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;span class="c"&gt;// Output&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="k"&gt;package&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gopher&lt;/span&gt;

&lt;span class="n"&gt;godotenv&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRONGEST_AVENGER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Just add the code at the end of the os package in the main function.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Viper Package
&lt;/h2&gt;

&lt;p&gt;Viper is one of the most popular packages in the golang community. Many Go projects are built using Viper including Hugo, Docker Notary, Mercury.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application and can handle all types of configuration needs and formats. Reading from JSON, TOML, YAML, HCL, envfile and Java properties config files&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more information read the official documentation of &lt;a href="https://github.com/spf13/viper"&gt;viper&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Install
&lt;/h3&gt;

&lt;p&gt;Open the terminal in the project root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;spf13&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;viper&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To set the config file and path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetConfigFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;".env"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To read the config file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadInConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get the value from the config file using key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the &lt;code&gt;main.go&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s"&gt;"fmt"&lt;/span&gt;
  &lt;span class="s"&gt;"log"&lt;/span&gt;
  &lt;span class="s"&gt;"os"&lt;/span&gt;

  &lt;span class="s"&gt;"github.com/joho/godotenv"&lt;/span&gt;
  &lt;span class="s"&gt;"github.com/spf13/viper"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// use viper package to read .env file&lt;/span&gt;
&lt;span class="c"&gt;// return the value of the key&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;viperEnvVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;// SetConfigFile explicitly defines the path, name and extension of the config file.&lt;/span&gt;
  &lt;span class="c"&gt;// Viper will use this and not check any of the config paths.&lt;/span&gt;
  &lt;span class="c"&gt;// .env - It will search for the .env file in the current directory&lt;/span&gt;
  &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetConfigFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;".env"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c"&gt;// Find and read the config file&lt;/span&gt;
  &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadInConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error while reading config file %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c"&gt;// viper.Get() returns an empty interface{}&lt;/span&gt;
  &lt;span class="c"&gt;// to get the underlying type of the key,&lt;/span&gt;
  &lt;span class="c"&gt;// we have to do the type assertion, we know the underlying value is string&lt;/span&gt;
  &lt;span class="c"&gt;// if we type assert to other type it will throw an error&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c"&gt;// If the type is a string then ok will be true&lt;/span&gt;
  &lt;span class="c"&gt;// ok will make sure the program not break&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid type assertion"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c"&gt;// os package  &lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;

  &lt;span class="c"&gt;// godotenv package&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;

  &lt;span class="c"&gt;// viper package read .env&lt;/span&gt;
  &lt;span class="n"&gt;viperenv&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viperEnvVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"STRONGEST_AVENGER"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"viper : %s = %s &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"STRONGEST_AVENGER"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viperenv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the terminal and run the &lt;code&gt;main.go&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;span class="c"&gt;// Output&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="k"&gt;package&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gopher&lt;/span&gt;

&lt;span class="n"&gt;godotenv&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRONGEST_AVENGER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thor&lt;/span&gt;

&lt;span class="n"&gt;viper&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRONGEST_AVENGER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Viper is not limited to .env files.
&lt;/h3&gt;

&lt;p&gt;It supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setting defaults&lt;/li&gt;
&lt;li&gt;reading from JSON, TOML, YAML, HCL, envfile and Java properties config files&lt;/li&gt;
&lt;li&gt;live watching and re-reading of config files (optional)&lt;/li&gt;
&lt;li&gt;reading from environment variables&lt;/li&gt;
&lt;li&gt;reading from remote config systems (etcd or Consul), and watching changes&lt;/li&gt;
&lt;li&gt;reading from command line flags&lt;/li&gt;
&lt;li&gt;reading from buffer&lt;/li&gt;
&lt;li&gt;setting explicit values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Viper can be thought of as a registry for all of your applications configuration needs.&lt;/p&gt;

&lt;p&gt;Let's experiment: 💣 &lt;/p&gt;

&lt;p&gt;Create a new &lt;code&gt;config.yaml&lt;/code&gt; file in the project root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;I_AM_INEVITABLE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;am&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Iron&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Man"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To set the config filename&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetConfigName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To set the config file path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Look in the current working directory&lt;/span&gt;
&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddConfigPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To read the config file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadInConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the &lt;code&gt;main.go&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// use viper package to load/read the config file or .env file and&lt;/span&gt;
&lt;span class="c"&gt;// return the value of the key&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;viperConfigVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;// name of config file (without extension)&lt;/span&gt;
  &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SetConfigName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c"&gt;// look for config in the working directory&lt;/span&gt;
  &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddConfigPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c"&gt;// Find and read the config file&lt;/span&gt;
  &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadInConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error while reading config file %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c"&gt;// viper.Get() returns an empty interface{}&lt;/span&gt;
  &lt;span class="c"&gt;// to get the underlying type of the key,&lt;/span&gt;
  &lt;span class="c"&gt;// we have to do the type assertion, we know the underlying value is string&lt;/span&gt;
  &lt;span class="c"&gt;// if we type assert to other type it will throw an error&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c"&gt;// If the type is a string then ok will be true&lt;/span&gt;
  &lt;span class="c"&gt;// ok will make sure the program not break&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid type assertion"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;// os package&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;

  &lt;span class="c"&gt;// godotenv package&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;

  &lt;span class="c"&gt;// viper package read .env&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;

  &lt;span class="c"&gt;// viper package read config file&lt;/span&gt;
  &lt;span class="n"&gt;viperconfig&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;viperConfigVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I_AM_INEVITABLE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  

  &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"viper config : %s = %s &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"I_AM_INEVITABLE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;viperconfig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the terminal and run the &lt;code&gt;main.go&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;span class="c"&gt;// Output&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="k"&gt;package&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gopher&lt;/span&gt;

&lt;span class="n"&gt;godotenv&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRONGEST_AVENGER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thor&lt;/span&gt;

&lt;span class="n"&gt;viper&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;STRONGEST_AVENGER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thor&lt;/span&gt;

&lt;span class="n"&gt;viper&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;I_AM_INEVITABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt; &lt;span class="n"&gt;am&lt;/span&gt; &lt;span class="n"&gt;Iron&lt;/span&gt; &lt;span class="n"&gt;Man&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it, now you can explore more of their secrets. If you find something worth sharing don't hesitate. &lt;/p&gt;

&lt;p&gt;The complete code is available in the &lt;a href="https://github.com/schadokar/blog-projects/tree/master/go-env-ways"&gt;github&lt;/a&gt;. &lt;/p&gt;




</description>
      <category>go</category>
      <category>viper</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to create a CLI in golang with cobra</title>
      <dc:creator>Shubham Chadokar</dc:creator>
      <pubDate>Tue, 07 Jan 2020 08:38:40 +0000</pubDate>
      <link>https://dev.to/schadokar/how-to-create-a-cli-in-golang-with-cobra-5bdi</link>
      <guid>https://dev.to/schadokar/how-to-create-a-cli-in-golang-with-cobra-5bdi</guid>
      <description>&lt;p&gt;Ever wanted to create your own cli.&lt;/p&gt;

&lt;p&gt;Check out my article published on Medium.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://towardsdatascience.com/how-to-create-a-cli-in-golang-with-cobra-d729641c7177"&gt;Article Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/schadokar"&gt;Shubham Chadokar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>cli</category>
      <category>cobra</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
