Skip to content

slack-io/proper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proper Build Status Go Report Card GoDoc License: MIT

A map[string]string decorator offering a collection of helpful functions to extract the values in different types

Features

  • Retrieve data from a string map, in String, Integer, Float and Boolean types.
  • Return a default value in case of missing keys or invalid types

Examples

package main

import (
	"fmt"
	"github.com/slack-io/proper"
)

func main() {
	parameters := make(map[string]string)
	parameters["boolean"] = "true"
	parameters["float"] = "1.2"
	parameters["integer"] = "11"
	parameters["string"] = "value"

	properties := proper.NewProperties(parameters)
	fmt.Println(properties.BooleanParam("boolean", false)) // true
	fmt.Println(properties.FloatParam("float", 0))         // 1.2
	fmt.Println(properties.IntegerParam("integer", 0))     // 11
	fmt.Println(properties.StringParam("string", ""))      // value
}