proper

package module
v0.0.0-...-6e70a05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2019 License: MIT Imports: 1 Imported by: 33

README

proper Build Status Go Report Card GoDoc

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/shomali11/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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Properties

type Properties struct {
	// contains filtered or unexported fields
}

Properties is a string map decorator

func NewProperties

func NewProperties(m map[string]string) *Properties

NewProperties creates a new Properties object

func (*Properties) BooleanParam

func (p *Properties) BooleanParam(key string, defaultValue bool) bool

BooleanParam attempts to look up a boolean value by key. If not found, return the default boolean value

func (*Properties) FloatParam

func (p *Properties) FloatParam(key string, defaultValue float64) float64

FloatParam attempts to look up a float value by key. If not found, return the default float value

func (*Properties) IntegerParam

func (p *Properties) IntegerParam(key string, defaultValue int) int

IntegerParam attempts to look up a integer value by key. If not found, return the default integer value

func (*Properties) StringParam

func (p *Properties) StringParam(key string, defaultValue string) string

StringParam attempts to look up a string value by key. If not found, return the default string value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL