Decodini is a Go library for decoding and encoding from and to different Go data structures. (WIP)
  • Go 99.8%
  • Just 0.2%
Find a file
lukasl-dev fe2ba74c21
Some checks failed
Go / build (push) Has been cancelled
Update README.md
2026-02-20 16:50:34 +01:00
.github/workflows Add -benchmem flag to gh action 2025-06-11 17:05:57 +02:00
assets Update decodini.png 2025-04-25 13:38:11 +02:00
bench Add simple benchmark for 'map to embedded struct' 2025-06-10 17:09:44 +02:00
pkg/decodini Address issue #5 2026-02-20 16:50:30 +01:00
.gitignore Initial commit 2025-01-04 01:47:14 +01:00
go.mod Implement tree encoding 2025-01-04 04:17:45 +01:00
go.sum Implement tree encoding 2025-01-04 04:17:45 +01:00
justfile Rename benchmarks 2025-05-02 18:25:36 +02:00
LICENSE Initial commit 2025-01-04 01:47:14 +01:00
README.md Update README.md 2026-02-20 16:50:34 +01:00

decodini

Go
decodini

Decodini is a small Go library for moving data between structs, maps, slices, and primitives.

It works in two steps internally: encode the source into a Tree, then decode that tree into the target type. Most users can just call Transmute.

Installation

go get github.com/lukasl-dev/decodini

Usage

The primary interface for the library is the Transmute function, which performs both encoding and decoding in a single step.

Basic Example

package main

import (
	"fmt"
	"github.com/lukasl-dev/decodini/pkg/decodini"
)

type UserSource struct {
	Username string
	Age      int
}

type UserTarget struct {
	Username string
	Age      int
}

func main() {
	src := UserSource{Username: "alice", Age: 30}
	
	// Transmute source into UserTarget
	dst, err := decodini.Transmute[UserTarget](nil, src)
	if err != nil {
		panic(err)
	}
	
	fmt.Printf("%+v\n", dst)
}

Struct Tags

Use the decodini struct tag to map fields that have different names in their respective structs. For a successful transmutation, the fields must resolve to the same name.

type Source struct {
	InternalName string `decodini:"name"`
}

type Target struct {
	ExternalName string `decodini:"name"`
	IgnoredField string `decodini:"-"`
}

Transmuting into Existing Values

Use TransmuteInto to populate an existing variable.

var target UserTarget
err := decodini.TransmuteInto(nil, src, &target)

Advanced Configuration

The Transmutation struct allows for customisation of the encoding and decoding behaviour.

tm := &decodini.Transmutation{
	Decoding: &decodini.Decoding{
		StructTag: "custom_tag",
	},
}

dst, err := decodini.Transmute[UserTarget](tm, src)

License

This project is licensed under the MIT License. See LICENSE for details.