/pathify

A Swiss knife to deal with the hassle of unstructured data

Primary LanguageGoApache License 2.0Apache-2.0

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.