Code Monkey home page Code Monkey logo

mowshon / dot Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 1.0 30 KB

Dot: A powerful Go package simplifying navigation and manipulation of complex data structures via dot-separated paths. Features include insertion into struct fields, maps, arrays, slices, and channels, along with robust error handling and support for diverse map keys.

License: MIT License

Go 100.00%
data-manipulation dot-notation go-data-structures go-lang go-package go-reflect go-utils reflection path-navigation

dot's People

Contributors

mowshon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ekousanakis

dot's Issues

unknown path: after map[string]any -> struct

Problem:

The code encounters an unknown path: Shelf.Orange.Qty error. This happens because the dot package might not be designed to handle nested maps where keys are object

package main

import (
	"fmt"

	"github.com/mowshon/dot"
)

type MyShopStock struct {
	Shelf     map[string]any
	Werehouse map[string]any
}

type Product struct {
	Price float64
	Name  string
	Qty   uint
}

type Inventory struct {
	Name string
	Qty  uint
}

func main() {
	data := &MyShopStock{
		Shelf: map[string]any{
			"Apple":  Product{Price: 1.99, Name: "apple", Qty: 10},
			"Banana": Product{Price: 0.99, Name: "banana", Qty: 5},
			"Orange": Product{},
		},
	}

	obj, err := dot.New(data)
	if err != nil {
		panic(err)
	}

	err = obj.Insert("Shelf.Orange.Qty", 5)
	if err != nil {
		panic(err)
	}

	fmt.Println(data.Shelf["Orange"])
}

https://go.dev/play/p/wBnrgKh67VU

Expected Behavior:

The Insert operation should successfully set the Qty for "Orange" to 5 without errors.

Observations:

It seems the dot package might not be handling nested maps as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.