Skip to content
/ spark Public

Common utilities for working with data in Go

License

Notifications You must be signed in to change notification settings

ex-vi/spark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spark

Go Version Go Doc Circle CI

Spark library includes common tools for working with data in Go. It will be updated whenever I need new utils or someone wants to bring new ones.

Usage

spark/structs - utilities for structs

Map function converts the given struct to a map[string]interface{}, where the keys of the map are the field names and the values of the map the associated values of the fields. The default key string is the struct field name but can be changed in the struct field's tag value. The structs key in the struct's field tag value is the key name.

s := struct {
    Age  int
    Name string
}{
    Age:  25,
    Name: "John Doe",
}

m := structs.Map(s)

age := m["Age"]
name := m["Name"]
s := struct {
    Age  int    `structs:"my-age"`
    Name string `structs:"my-name"`
}{
    Age:  25,
    Name: "John Doe",
}

m := structs.Map(s)

age := m["my-age"]
name := m["my-name"]