Skip to content

A Swiss knife to deal with the hassle of unstructured data

License

Notifications You must be signed in to change notification settings

astrokube/pathify

Repository files navigation

GitHub Release Go Reference go.mod License Build Status CodeQL

Pathify

The swiss knife to deal with the hassle of unstructured data.

History and project status

This module is already ready-for-production and the astrokube organization already take advantage of it for our internal projects.

Pathify Highlights

  • Easy integration: It's straightforward to be integrated with your current developments.

Installation

Use go get to retrieve the library to add it to your GOPATH workspace, or project's Go module dependencies.

go get -u github.com/astrokube/pathifier

To update the library use go get -u to retrieve the latest version of it.

go get -u github.com/astrokube/pathifier

You could specify a concrete version of this module as It's shown on the below. Replace x.y.z by the desired version.

module github.com/<org>/<repository>
require ( 
  github.com/astrokube/pathifier vX.Y.Z
)

Getting started

Pre-requisites

  • Go 1.19+

Examples

A rich and growing set of examples of usage of this module can be found in folder examples.

package main

import (
	"strings"

	"github.com/astrokube/pathify"
)

var peopleArray = []any{
	map[string]any{
		"firstname": "John",
		"lastname":  "Doe",
		"age":       29,
	},
	map[string]any{
		"firstname": "Jane",
		"lastname":  "Moe",
		"age":       30,
	},
}

func main() {
	p := pathify.Load[[]any](peopleArray).Set(
		"[1].lastname", "Doe",
		"[0].firstname", "Wendy",
		"[2].firstname", "Cindy",
		"[1].firstname", strings.ToUpper,
	)
	b, _ := p.YAML()
	println(string(b))
	b, _ = p.JSON()
	println(string(b))
}

Output

- age: 29
  firstname: Wendy
  lastname: Doe
- age: 30
  firstname: JANE
  lastname: Doe
- firstname: Cindy
[{"age":29,"firstname":"Wendy","lastname":"Doe"},{"age":30,"firstname":"JANE","lastname":"Doe"},{"firstname":"Cindy"}]

Contributing

See the contributing documentation.