pointerstructure

Go library for addressing and reading/writing a specific value within any Go structure using a string syntax.

  • Owner: mitchellh/pointerstructure
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

pointerstructure GoDoc

pointerstructure is a Go library for identifying a specific value within
any Go structure using a string syntax.

pointerstructure is based on
JSON Pointer (RFC 6901), but
reimplemented for Go.

The goal of pointerstructure is to provide a single, well-known format
for addressing a specific value. This can be useful for user provided
input on structures, diffs of structures, etc.

Features

  • Get the value for an address

  • Set the value for an address within an existing structure

  • Delete the value at an address

  • Sorting a list of addresses

Installation

Standard go get:

$ go get github.com/mitchellh/pointerstructure

Usage & Example

For usage and examples see the Godoc.

A quick code example is shown below:

complex := map[string]interface{}{
	"alice": 42,
	"bob": []interface{}{
		map[string]interface{}{
			"name": "Bob",
		},
	},
}

value, err := pointerstructure.Get(complex, "/bob/0/name")
if err != nil {
	panic(err)
}

fmt.Printf("%s", value)
// Output:
// Bob

Continuing the example above, you can also set values:

value, err = pointerstructure.Set(complex, "/bob/0/name", "Alice")
if err != nil {
	panic(err)
}

value, err = pointerstructure.Get(complex, "/bob/0/name")
if err != nil {
	panic(err)
}

fmt.Printf("%s", value)
// Output:
// Alice

Main metrics

Overview
Name With Ownermitchellh/pointerstructure
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2017-02-04 14:23:10
Pushed At2023-09-06 00:53:42
Last Commit At2021-11-02 08:57:21
Release Count5
Last Release Namev1.2.1 (Posted on )
First Release Namev1.0.0 (Posted on )
用户参与
Stargazers Count214
Watchers Count5
Fork Count12
Commits Count31
Has Issues Enabled
Issues Count4
Issue Open Count1
Pull Requests Count7
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private