pointerstructure

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

  • 所有者: mitchellh/pointerstructure
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者mitchellh/pointerstructure
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-02-04 14:23:10
推送于2023-09-06 00:53:42
最后一次提交2021-11-02 08:57:21
发布数5
最新版本名称v1.2.1 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数214
关注者数5
派生数12
提交数31
已启用问题?
问题数4
打开的问题数1
拉请求数7
打开的拉请求数0
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?