dotmap

package module
v0.0.0-...-f4e83cb Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: GPL-3.0 Imports: 2 Imported by: 0

README

dotmap

dotmap

A Dot notation compatible concurrent safe Hashmap in pure Go

Latest release

Download

TL;DR

package main

import (
	"fmt"
	"github.com/zerjioang/dotmap"
)

func main(){
	mm := dotmap.New()
	mm.Reset(map[string]interface{}{
		"foo": "bar",
		"enableDebug": false,
		"version": 1.0,
		"config": map[string]interface{}{
			"http": 2,
		},
	})
	v, found := dotmap.GetDotMap(mm, "config.http")
	fmt.Println("key found: ", found)
	fmt.Println("key value: ", v)
	v2, found2 := dotmap.GetDotMap(mm, "config.key")
	fmt.Println("key found: ", found2)
	fmt.Println("key value: ", v2)
}

and prints in terminal std out:

key found:  true
key value:  2
key found:  false
key value:  <nil>

Licenses

All rights reserved to @zerjioang under GNU GPL v3 license

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Uses GPLv3 license described below

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDotMap

func GetDotMap(mm *ConcurrentMap, k string) (interface{}, bool)

Reads internal configuration map key with given value

func UpdateDotMap

func UpdateDotMap(mm *ConcurrentMap, key []string, value string) error

Updates internal configuration map key with given value

Types

type ConcurrentMap

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

func New

func New() *ConcurrentMap

func (*ConcurrentMap) Bytes

func (mm *ConcurrentMap) Bytes(marshal func(v interface{}) ([]byte, error)) ([]byte, error)

concurrent safe marshal function that serializes dotmap to requested format

func (*ConcurrentMap) CreateChain

func (mm *ConcurrentMap) CreateChain(key []string, lastValid int, value interface{})

Creates a new key chain for non existing keys

func (*ConcurrentMap) Get

func (mm *ConcurrentMap) Get(key string) (interface{}, bool)

concurrent safe of key readings from the map

func (*ConcurrentMap) Reset

func (mm *ConcurrentMap) Reset(data map[string]interface{})

Resets map content data

func (*ConcurrentMap) Set

func (mm *ConcurrentMap) Set(key string, value interface{})

concurrent safe set of a key on the map

type Map

type Map map[string]interface{}

overloading go map implementation same as go, not safe for concurrent access please use ConcurrentMap for concurrent access

func (*Map) Bytes

func (mm *Map) Bytes(marshal func(v interface{}) ([]byte, error)) ([]byte, error)

marshal function that serializes dotmap to requested format

func (*Map) Get

func (mm *Map) Get(key string) (interface{}, bool)

concurrent NOT safe set of a key on the map

func (*Map) GetChild

func (mm *Map) GetChild(key string) (*Map, bool)

concurrent safe of key readings from the map

func (*Map) Set

func (mm *Map) Set(key string, value interface{})

concurrent NOT safe set of a key on the map

Directories

Path Synopsis
examples
hello-world command

Jump to

Keyboard shortcuts

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