<?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>The Ops Community ⚙️: Neo</title>
    <description>The latest articles on The Ops Community ⚙️ by Neo (@neo7337).</description>
    <link>https://community.ops.io/neo7337</link>
    <image>
      <url>https://community.ops.io/images/XvVPi84ukS32ByNfcDOkxJ4nnV8IJ2Dryns4uUfqpPs/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS8xNzcvYTFm/MDI4YWEtYTZkNC00/YjRlLWEwMmQtYTRk/ZDU4Y2NiZWYwLnBu/Zw</url>
      <title>The Ops Community ⚙️: Neo</title>
      <link>https://community.ops.io/neo7337</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/neo7337"/>
    <language>en</language>
    <item>
      <title>Devops and Golang</title>
      <dc:creator>Neo</dc:creator>
      <pubDate>Thu, 26 May 2022 02:44:41 +0000</pubDate>
      <link>https://community.ops.io/neo7337/devops-and-golang-363o</link>
      <guid>https://community.ops.io/neo7337/devops-and-golang-363o</guid>
      <description>&lt;p&gt;Configuration files play an important role in the application development lifecycle. We build and deploy applications onto multiple environments and each of them must require a certain set of configurations to run.&lt;/p&gt;

&lt;p&gt;Running applications on multiple environments require configuration to be set properly.&lt;/p&gt;

&lt;p&gt;Golang builds a single binary of the whole application which can be run on the specific environment be it a linux binary or a windows binary.&lt;/p&gt;

&lt;p&gt;With the release of Golang v1.16 Embed feature was also released and with that we can mount the config files onto a structure in our program while building the binary itself and we do not need to ship the configuration files explicitly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read configuration files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The below snippet can help you read the configuration file using the embed package.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application Structure&lt;/em&gt;&lt;br&gt;
&lt;a href="https://community.ops.io/images/xxC9LoCR535V602o5M3UTR2ulIOoAcvpvX_OnZJ_EPc/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvaWMz/bXUwbnQzZ3ZpeWZ2/N2cwM2UucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/xxC9LoCR535V602o5M3UTR2ulIOoAcvpvX_OnZJ_EPc/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvaWMz/bXUwbnQzZ3ZpeWZ2/N2cwM2UucG5n" alt="image" width="143" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;config.yaml&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Test_User
age: 73
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;main.go&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

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

import (
    ...
    &amp;lt;imports&amp;gt;
)

//go:embed config.yaml
var config embed.FS

type Conf struct {
    Name string `yaml:"name"`
    Age  int    `yaml:"name"`
}

func main() {
    var configs Conf
    configs.readConfig()
    fmt.Println(configs)
}

func (conf *Conf) readConfig() *Conf {
    yamlFile, err := config.ReadFile("config.yaml")
    if err != nil {
        log.Fatalln(err)
    }
    err = yaml.Unmarshal(yamlFile, &amp;amp;conf)
    if err != nil {
        log.Fatalln(err)
    }
    return conf
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build the binary and we don't need to worry about shipping the config.yaml while deploying our applications on any platform.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>go</category>
      <category>tutorials</category>
      <category>cloudops</category>
    </item>
  </channel>
</rss>
