Skip to content

JosiahWitt/priv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

priv

Privatize data in your Go (Golang) application

Build Status codecov Maintainability GoDoc License: MIT

Under development; API may change.

go get github.com/JosiahWitt/priv

Tested with Go 1.9, 1.10, and 1.11.

About

Currently priv exports a simple API, which is composed of priv.ToMap and priv.ToMapErr. priv.ToMap panics if a field that does not exist is requested, whereas priv.ToMapErr returns an error. Most of the time panicing is not a big deal, since it would indicate a typo in the code.

These functions allow mapping structs and arrays/slices of structs to map[string]interface{} and []map[string]interface{}{}, respectively. One example of using priv is if you only want to expose certain fields at an API endpoint.

Example

users := [User{ID: "123", Some: {Nested: {Field: "abc"}}, SomethingElse: true}]
v := priv.ToMap(users, "ID", "Some.Nested.Field->Renamed.Location")
// Thus, v = [{ID: "123", Renamed: {Location: "abc"}}]

About

Privatize data in your Go application

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages