Elian  Harber

Elian Harber

1647159540

INI: INI Parser for Golang

INI Parser & Reader Writer Library

ini parser and Reader Writer library for Golang,easy-use,fast  

Features

  • Read by []byte
  • Read by file
  • Supports file monitoring and takes effect in real time without reloading
  • Unmarshal to Struct
  • Marshal to Json
  • Write to File

Installation

go get github.com/wlevene/ini

Example

import (
    "fmt"
    "github.com/wlevene/ini"
)

GetValue

doc := `
[section]
k=v

[section1]
k1=v1
k2=1
k3=3.5
k4=0.0.0.0
`
v1 := ini.New().Load([]byte(doc)).Section("section1").Get("k1")
fmt.Println(v1)

Output

v1
i := ini.New().Load([]byte(doc))
v1 := i.Section("section1").Get("k1")
v2 := i.GetInt("k2")
v3 := i.GetFloat64("k3")
v4 := i.Get("k4")
v5 := i.GetIntDef("keyint", 10)
v6 := i.GetDef("keys", "defualt")

fmt.Printf("v1:%v v2:%v v3:%v v4:%v v5:%v v6:%v\n", v1, v2, v3, v4, v5, v6)

Output

v1:v1 v2:1 v3:3.5 v4:0.0.0.0 v5:10 v6:defualt

Marshal2Json

fmt.Println(string(i.Marshal2Json()))

Output

{"section":{"k":"v"},"section1":{"k1":"v1","k2":"1","k3":"3.5","k4":"0.0.0.0"}}

Unmarshal Struct

type TestConfig struct {
    K    string  `ini:"k" json:"k,omitempty"`
    K1   int     `ini:"k1" json:"k1,omitempty"`
    K2   float64 `ini:"k2"`
    K3   int64   `ini:"k3"`
    User User    `ini:"user"`
}

type User struct {
    Name string `ini:"name"`
    Age  int    `ini:"age"`
}
doc := `
k=v
k1=2
k2=2.2
k3=3

[user]
name=tom
age=-23
`

cfg := TestConfig{}

ini.Unmarshal([]byte(doc), &cfg)
fmt.Println("cfg:", cfg)

Output

cfg: {v 2 2.2 3 {tom -23}}

Parse File

ini file

; this is comment
; author levene 
; date 2021-8-1


a='23'34?::'<>,.'
c=d

[s1]
k=67676
k1 =fdasf 
k2= sdafj3490&@)34 34w2

# comment 
# 12.0.0.1
[s2]

k=3


k2=945
k3=-435
k4=0.0.0.0

k5=127.0.0.1
k6=levene@github.com

k7=~/.path.txt
k8=./34/34/uh.txt

k9=234@!@#$%^&*()324
k10='23'34?::'<>,.'
file := "./test.ini"
ini.New().LoadFile(file).Section("s2").Get("k2")

fmt.Println(string(ini.Marshal2Json()))

Output

945

Watch File

file := "./test.ini"

idoc := ini.New().WatchFile(file)
v := idoc.Section("s2").Get("k1")
fmt.Println("v:", v1)

// modify k1=v1   ==> k1=v2
time.Sleep(10 * time.Second)

v = idoc.Section("s2").Get("k1")
fmt.Println("v:", v1)

Output

v: v1
v: v2

Print file with json

file := "./test.ini"
fmt.Println(string(ini.New().LoadFile(file).Marshal2Json()))

Output

{
  "a": "'23'34?::'<>,.'",
  "c": "d",
  "s1": {
    "k": "67676",
    "k2": "34w2"
  },
  "s2": {
    "k": "3",
    "k10": "'23'34?::'<>,.'",
    "k2": "945",
    "k3": "-435",
    "k4": "0.0.0.0",
    "k5": "127.0.0.1",
    "k6": "levene@github.com",
    "k7": "~/.path.txt",
    "k8": "./34/34/uh.txt",
    "k9": "234@!@#$%^&*()324"
  }
}

Set Ini

doc := `
k =v
[section]
a=b
c=d
`
ini := New().Load([]byte(doc)).Section("section")
fmt.Println("--------------------------------")
ini.Dump()

fmt.Println("--------------------------------")
ini.Set("a", 11).Set("c", 12.3).Section("").Set("k", "SET")
ini.Dump()

v := ini.Section("section").GetInt("a")

if v != 11 {
    t.Errorf("Error: %d", v)
}

v1 := ini.GetFloat64("c")

if v1 != 12.3 {
    t.Errorf("Error: %f", v1)
}

v2 := ini.Section("").Get("k")
if v2 != "SET" {
    t.Errorf("Error: %s", v2)
}

Wirte Ini

filename := "./save.ini"
ini := New().Set("a1", 1)
ini.Save(filename)
fmt.Println(ini.Err())

ini2 := New().Set("a1", 1).Section("s1").Set("a2", "v2")
ini2.Save(filename)
fmt.Println(ini2.Err())

// ------

doc := `
; 123
c11=d12312312
# 434

[section]
k=v
; dsfads 
;123
#3452345


[section1]
k1=v1

[section3]
k3=v3
`
ini3 := New().Load([]byte(doc))
ini.Save("./save.ini")

file content


; 123
c11 = d12312312

# 434
[section]
k = v

; dsfads 
;123
#3452345
[section1]
k1 = v1

[section3]
k3 = v3

Dump AST struct

INIDocNode {
    CommentNode {
        Comment: ; this is comment
        Line: 0
    }
    CommentNode {
        Comment: ; author levene
        Line: 1
    }
    CommentNode {
        Comment: ; date 2021-8-1
        Line: 2
    }
    KVNode {
        Key: a
        Value: '23'34?::'<>,.'
        Line: 5
    }
    KVNode {
        Key: c
        Value: d
        Line: 6
    }
    Section {
        Section: [s1]
        Line: 8
        KVNode {
            Value: 67676
            Line: 9
            Key: k
        }
        KVNode {
            Key: k1
            Value: fdasf
            Line: 10
        }
        KVNode {
            Value: 4w2
            Line: 11
            Key: k2
        }
    }
    CommentNode {
        Comment: # comment
        Line: 13
    }
    CommentNode {
        Line: 14
        Comment: # 12.0.0.1
    }
    Section {
        Section: [s2]
        Line: 15
        KVNode {
            Value: 3
            Line: 17
            Key: k
        }
        KVNode {
            Value: 945
            Line: 20
            Key: k2
        }
        KVNode {
            Key: k3
            Value: -435
            Line: 21
        }
        KVNode {
            Line: 22
            Key: k4
            Value: 0.0.0.0
        }
        KVNode {
            Line: 24
            Key: k5
            Value: 127.0.0.1
        }
        KVNode {
            Key: k6
            Value: levene@github.com
            Line: 25
        }
        KVNode {
            Key: k7
            Value: ~/.path.txt
            Line: 27
        }
        KVNode {
            Line: 28
            Key: k8
            Value: ./34/34/uh.txt
        }
        KVNode {
            Key: k9
            Value: 234@!@#$%^&*()324
            Line: 30
        }
        KVNode {
            Key: k10
            Value: '23'34?::'<>,.'
            Line: 31
        }
    }
}

Author: Wlevene
Source Code: https://github.com/wlevene/ini 
License: MIT License

#go #golang #config 

What is GEEK

Buddha Community

INI: INI Parser for Golang

Hire Dedicated Golang Developers | Golang Web Development Company

Does your business need a robust system across large-scale network servers then developing your app with a Golang programming language is the way to go. Golang is generally used for the development of highly secured, High Speed and High Modularity apps such as a FinTech Industry.

Want to develop a Highly secured app for your business?

Then hire a dedicated Golang developer from WebClues Infotech that are highly skilled in carrying out the work in a timely and qualitative output. With WebClues Infotech you get the assurance that we know what are the customers’ expectations and how to deliver on them on time.

Get your desired Golang Developer based on your project requirement!!

Share your requirements here https://www.webcluesinfotech.com/contact-us/

Book Free Interview with Golang developer: https://bit.ly/3dDShFg

#hire golang developer #hire go language developer #dedicated golang app developers #golang web development company #hire golang developers india #hire expert golang developers

Golang Web Development:Th Best Programming Language in 2020

https://www.mobinius.com/blogs/golang-web-development-company

#golang web development #golang-app-development-company #golang-development-solutions #hire-golang-developers #golang-development-services

Elian  Harber

Elian Harber

1647159540

INI: INI Parser for Golang

INI Parser & Reader Writer Library

ini parser and Reader Writer library for Golang,easy-use,fast  

Features

  • Read by []byte
  • Read by file
  • Supports file monitoring and takes effect in real time without reloading
  • Unmarshal to Struct
  • Marshal to Json
  • Write to File

Installation

go get github.com/wlevene/ini

Example

import (
    "fmt"
    "github.com/wlevene/ini"
)

GetValue

doc := `
[section]
k=v

[section1]
k1=v1
k2=1
k3=3.5
k4=0.0.0.0
`
v1 := ini.New().Load([]byte(doc)).Section("section1").Get("k1")
fmt.Println(v1)

Output

v1
i := ini.New().Load([]byte(doc))
v1 := i.Section("section1").Get("k1")
v2 := i.GetInt("k2")
v3 := i.GetFloat64("k3")
v4 := i.Get("k4")
v5 := i.GetIntDef("keyint", 10)
v6 := i.GetDef("keys", "defualt")

fmt.Printf("v1:%v v2:%v v3:%v v4:%v v5:%v v6:%v\n", v1, v2, v3, v4, v5, v6)

Output

v1:v1 v2:1 v3:3.5 v4:0.0.0.0 v5:10 v6:defualt

Marshal2Json

fmt.Println(string(i.Marshal2Json()))

Output

{"section":{"k":"v"},"section1":{"k1":"v1","k2":"1","k3":"3.5","k4":"0.0.0.0"}}

Unmarshal Struct

type TestConfig struct {
    K    string  `ini:"k" json:"k,omitempty"`
    K1   int     `ini:"k1" json:"k1,omitempty"`
    K2   float64 `ini:"k2"`
    K3   int64   `ini:"k3"`
    User User    `ini:"user"`
}

type User struct {
    Name string `ini:"name"`
    Age  int    `ini:"age"`
}
doc := `
k=v
k1=2
k2=2.2
k3=3

[user]
name=tom
age=-23
`

cfg := TestConfig{}

ini.Unmarshal([]byte(doc), &cfg)
fmt.Println("cfg:", cfg)

Output

cfg: {v 2 2.2 3 {tom -23}}

Parse File

ini file

; this is comment
; author levene 
; date 2021-8-1


a='23'34?::'<>,.'
c=d

[s1]
k=67676
k1 =fdasf 
k2= sdafj3490&@)34 34w2

# comment 
# 12.0.0.1
[s2]

k=3


k2=945
k3=-435
k4=0.0.0.0

k5=127.0.0.1
k6=levene@github.com

k7=~/.path.txt
k8=./34/34/uh.txt

k9=234@!@#$%^&*()324
k10='23'34?::'<>,.'
file := "./test.ini"
ini.New().LoadFile(file).Section("s2").Get("k2")

fmt.Println(string(ini.Marshal2Json()))

Output

945

Watch File

file := "./test.ini"

idoc := ini.New().WatchFile(file)
v := idoc.Section("s2").Get("k1")
fmt.Println("v:", v1)

// modify k1=v1   ==> k1=v2
time.Sleep(10 * time.Second)

v = idoc.Section("s2").Get("k1")
fmt.Println("v:", v1)

Output

v: v1
v: v2

Print file with json

file := "./test.ini"
fmt.Println(string(ini.New().LoadFile(file).Marshal2Json()))

Output

{
  "a": "'23'34?::'<>,.'",
  "c": "d",
  "s1": {
    "k": "67676",
    "k2": "34w2"
  },
  "s2": {
    "k": "3",
    "k10": "'23'34?::'<>,.'",
    "k2": "945",
    "k3": "-435",
    "k4": "0.0.0.0",
    "k5": "127.0.0.1",
    "k6": "levene@github.com",
    "k7": "~/.path.txt",
    "k8": "./34/34/uh.txt",
    "k9": "234@!@#$%^&*()324"
  }
}

Set Ini

doc := `
k =v
[section]
a=b
c=d
`
ini := New().Load([]byte(doc)).Section("section")
fmt.Println("--------------------------------")
ini.Dump()

fmt.Println("--------------------------------")
ini.Set("a", 11).Set("c", 12.3).Section("").Set("k", "SET")
ini.Dump()

v := ini.Section("section").GetInt("a")

if v != 11 {
    t.Errorf("Error: %d", v)
}

v1 := ini.GetFloat64("c")

if v1 != 12.3 {
    t.Errorf("Error: %f", v1)
}

v2 := ini.Section("").Get("k")
if v2 != "SET" {
    t.Errorf("Error: %s", v2)
}

Wirte Ini

filename := "./save.ini"
ini := New().Set("a1", 1)
ini.Save(filename)
fmt.Println(ini.Err())

ini2 := New().Set("a1", 1).Section("s1").Set("a2", "v2")
ini2.Save(filename)
fmt.Println(ini2.Err())

// ------

doc := `
; 123
c11=d12312312
# 434

[section]
k=v
; dsfads 
;123
#3452345


[section1]
k1=v1

[section3]
k3=v3
`
ini3 := New().Load([]byte(doc))
ini.Save("./save.ini")

file content


; 123
c11 = d12312312

# 434
[section]
k = v

; dsfads 
;123
#3452345
[section1]
k1 = v1

[section3]
k3 = v3

Dump AST struct

INIDocNode {
    CommentNode {
        Comment: ; this is comment
        Line: 0
    }
    CommentNode {
        Comment: ; author levene
        Line: 1
    }
    CommentNode {
        Comment: ; date 2021-8-1
        Line: 2
    }
    KVNode {
        Key: a
        Value: '23'34?::'<>,.'
        Line: 5
    }
    KVNode {
        Key: c
        Value: d
        Line: 6
    }
    Section {
        Section: [s1]
        Line: 8
        KVNode {
            Value: 67676
            Line: 9
            Key: k
        }
        KVNode {
            Key: k1
            Value: fdasf
            Line: 10
        }
        KVNode {
            Value: 4w2
            Line: 11
            Key: k2
        }
    }
    CommentNode {
        Comment: # comment
        Line: 13
    }
    CommentNode {
        Line: 14
        Comment: # 12.0.0.1
    }
    Section {
        Section: [s2]
        Line: 15
        KVNode {
            Value: 3
            Line: 17
            Key: k
        }
        KVNode {
            Value: 945
            Line: 20
            Key: k2
        }
        KVNode {
            Key: k3
            Value: -435
            Line: 21
        }
        KVNode {
            Line: 22
            Key: k4
            Value: 0.0.0.0
        }
        KVNode {
            Line: 24
            Key: k5
            Value: 127.0.0.1
        }
        KVNode {
            Key: k6
            Value: levene@github.com
            Line: 25
        }
        KVNode {
            Key: k7
            Value: ~/.path.txt
            Line: 27
        }
        KVNode {
            Line: 28
            Key: k8
            Value: ./34/34/uh.txt
        }
        KVNode {
            Key: k9
            Value: 234@!@#$%^&*()324
            Line: 30
        }
        KVNode {
            Key: k10
            Value: '23'34?::'<>,.'
            Line: 31
        }
    }
}

Author: Wlevene
Source Code: https://github.com/wlevene/ini 
License: MIT License

#go #golang #config 

Ajay Kapoor

1624960485

Golang vs. Node.JS: Who Trumps the Battle of Backend Frameworks?

Full blog here

The backend of your application is truly the essential part of your product. No matter how much you appreciate the design, the application’s success lies in its backend. A scalable backend that effectively implements the required business logic is the primary goal of programmers.

Therefore, it is crucial to choose the most powerful and scalable technology. There are plenty of languages ​​in the market that can form the backend of any application, Node.js and Golang are the two most popular technologies among them.

They are real and developed languages ​​that have recently been used in various outstanding projects. Golang is an open-source programming language, whereas Node.js is an open-source server framework. They both are gaining popularity for various reasons.

According to a development stat, it is observed that almost 50% out of 58,543 respondents use Node.js as their preferred app development tool.

Golang, on the other hand, has overtaken other programming languages in the application development market and has gained huge recognition over the past few years.

But, which backend framework is best for you? In this article, I’ll make a healthy comparison of two of Google’s most popular backend development tools based on several essential features and various other factors.

Golang developers for hire

#best backend frameworks #node or golang #golang or nodejs #nodejs vs golang #golang vs nodejs #top backend frameworks

Fannie  Zemlak

Fannie Zemlak

1599732000

“Go Has Indeed Become The Language Of Cloud Infrastructure“ - Rob Pike

Introduction

We spoke to Rob Pike, the co-author of the Go programming language, about a career spanning four decades, the evolution of Go over the last ten years, and into the future.

The Interview

Evrone: Unlike many developers today, you started your career decades ago at Bell Labs. What’s been the biggest change in the way we develop software that you can think of, given your rare perspective?

**Rob: **The scale is much bigger today. Not just of the computers and the network, but the programs themselves. All of Unix version 6 (circa 1975) fits comfortably on a single RK05 disk pack, which has just over 2MB of storage, with lots of room left over for user software. And that was a fine computing environment, or at least seemed like one at the time. Although I can, of course, explain much of the growth, it is astonishing and perhaps not all of it is justified.

#golang #golang-api #golang-tools #golang-website #rob-pike #interview-transcript-go #latest-tech-stories #cloud-infrastructure-and-go