Documentation
¶
Overview ¶
Package tparse implements data structures and simple functions to parse toml like syntax
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dict ¶
Dict Type is used for containing the whole toml like data
func NewDict ¶
func NewDict() *Dict
NewDict returns the pointer to a Dict instance after initializing it.
func (Dict) Find ¶
Find returns Entries if found and an error if not for a given heading.
Example ¶
package main
import (
"fmt"
"github.com/shivam07a/tparse"
)
func main() {
tomlStr := `[Linus Torvalds]
Found = Linux, git
[Guido Van Rossum]
Found = Python, Gerrit
[Larry Wall]
Found = Perl`
var dict *tparse.Dict = tparse.NewDict()
err := dict.Parse(tomlStr)
if err != nil {
fmt.Println(err)
}
e, err := dict.Find("Linus Torvalds")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(e)
}
Output: map[Found:Linux, git]
func (Dict) Parse ¶
Parse is used to parse the content and store it in the Dict variable.
Example ¶
package main
import (
"fmt"
"github.com/shivam07a/tparse"
)
func main() {
tomlStr := `[Linus Torvalds]
Found = Linux, git
[Guido Van Rossum]
Found = Python, Gerrit
[Larry Wall]
Found = Perl`
var dict *tparse.Dict = tparse.NewDict()
err := dict.Parse(tomlStr)
if err != nil {
fmt.Println(err)
}
}
Output:
func (Dict) UnMarshal ¶
UnMarshal writes the data as a toml structured text in a io.Writer
Example ¶
tomlStr := `[Linus Torvalds]
Found = Linux, git
[Guido Van Rossum]
Found = Python, Gerrit
[Larry Wall]
Found = Perl`
var dict *tparse.Dict = tparse.NewDict()
err := dict.Parse(tomlStr)
if err != nil {
fmt.Println(err)
return
}
if err := d.UnMarshal(os.Stdout); err != nil {
fmt.Println(err)
return
}
Output: [Linus Torvalds] Found = Linux, git [Guido Van Rossum] Found = Python, Gerrit [Larry Wall] Found = Perl
type Entries ¶
Entries Type is used for containing the key value pairs
func (Entries) Find ¶
Find returns value for the given string from the entries data structure. If not found it returns an empty string and an error.
Example ¶
package main
import (
"fmt"
"github.com/shivam07a/tparse"
)
func main() {
tomlStr := `[Linus Torvalds]
Found = Linux, git
[Guido Van Rossum]
Found = Python, Gerrit
[Larry Wall]
Found = Perl`
var dict *tparse.Dict = tparse.NewDict()
err := dict.Parse(tomlStr)
if err != nil {
fmt.Println(err)
}
e, err := dict.Find("Linus Torvalds")
if err != nil {
fmt.Println(err)
return
}
found, err := e.Find("Found")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(found)
}
Output: Linux, git
Click to show internal directories.
Click to hide internal directories.