keyvalue

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 4 Imported by: 3

README

Noob-KeyValue

Go Reference GitHub go.mod Go version (subdirectory of monorepo) GitHub release (latest by date)

Noob KeyValue is utilities for golang to working with Map data-types with String Keys (map[string]interface{}), such as:

  • Assigning Map to Map
  • Creating Map from Struct
  • Getting Keys of a Map or Struct
  • Getting Values of a Map or Struct
  • Unmarshalling Map to Struct

Contents

Installation

To install this package, you need to install Go (version 1.17+ is required) & initiate your Go workspace first.

  1. After you initiate your workspace then you can install this package with below command.
go get -u github.com/alfarih31/nb-go-keyvalue
  1. Import it in your code
import "github.com/alfarih31/nb-go-keyvalue"

Quick Start & Usage

See the test: keyvalue_test.go

Contributors

License

This project is licensed under the - see the LICENSE.md file for details

Documentation

Overview

Package keyvalue provide an ability to working with Key-Value pair in golang `map[string]interface{} types`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAbleToConvert

func IsAbleToConvert(p interface{}) bool

IsAbleToConvert check whether an interface could be able to cast to KeyValue

Types

type KeyValue

type KeyValue map[string]interface{}

func FromStruct

func FromStruct(strct interface{}) (KeyValue, error)

FromStruct create a KeyValue from Struct

func (KeyValue) Assign

func (k KeyValue) Assign(source KeyValue, replaceExist ...bool)

Assign will assign Value by other KeyValue. This method inspired by JavaScript `Object.assign()` method Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

func (KeyValue) AssignTo

func (k KeyValue) AssignTo(target KeyValue, replaceExist ...bool)

AssignTo will assign Value from a KeyValue to other KeyValue with corresponding `Key`. This method is an opposite of Assign and return value by `in-place` operation.

func (KeyValue) JSON

func (k KeyValue) JSON() map[string]string

JSON return `map[string]string` as represent of JSON object

func (KeyValue) Keys

func (k KeyValue) Keys() []string

Keys return Array of Keys of KeyValue

func (KeyValue) String

func (k KeyValue) String() string

String method will format the KeyValue in JSON format when calling such methods `string(KeyValue)` or fmt.Println(KeyValue)`

func (KeyValue) ToMap

func (k KeyValue) ToMap() map[string]interface{}

ToMap return `map[string]interface{}` as purpose to cast back KeyValue

func (KeyValue) Unmarshal

func (k KeyValue) Unmarshal(i interface{}) error

Unmarshal KeyValue to a Struct

func (KeyValue) Values

func (k KeyValue) Values() []interface{}

Values return Array of Values of KeyValue

Jump to

Keyboard shortcuts

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