Help us shape the future of Go! Take the 2026 Go Developer Survey

akashi

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 8 Imported by: 1

README

灯 - Akashi

Go Reference

akashi is a Go library that provides a utility to compute and display the differences between two Go values. The core functionality is exposed through the DiffString function.

Features

  • Compares two Go values of any type.
  • Returns a human-readable string representing the differences.
  • Supports the fmt.Stringer interface for readable output. For example, time.Time values are displayed as time.Time("2025-02-03 23:03:15 +0000 UTC").

Installation

To install akashi, use go get:

go get github.com/seiyab/akashi

Usage

The primary function in this library is DiffString. It takes two interface{} values and an optional list of Options.

package main

import (
	"fmt"
	"github.com/seiyab/akashi"
)

func main() {
	type User struct {
		ID           string
		Name         string
		RegisteredAt time.Time
	}

	obj1 := User{
		ID:           "123",
		Name:         "Alice",
		RegisteredAt: time.Date(2025, 2, 3, 23, 3, 15, 0, time.UTC),
	}
	obj2 := User{
		ID:           "123",
		Name:         "Alice",
		RegisteredAt: time.Date(2024, 12, 19, 5, 45, 50, 0, jst),
	}

	diff = akashi.DiffString(obj1, obj2)

	fmt.Println(diff)
	// Output:
	//   akashi_test.User{
	//     ID: "123",
	//     Name: "Alice",
	// -   RegisteredAt: time.Time("2025-02-03 23:03:15 +0000 UTC"),
	// +   RegisteredAt: time.Time("2024-12-19 05:45:50 +0900 JST"),
	//   }
}
DiffString
func DiffString(x, y interface{}, options ...Option) string

DiffString returns a string that represents the difference between x and y. You can pass Options to customize the diffing process and output.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the LICENSE file.

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"github.com/seiyab/akashi"
)

type User struct {
	ID           string
	Name         string
	RegisteredAt time.Time
}

func main() {
	s := akashi.DiffString(
		User{
			ID:           "123",
			Name:         "Alice",
			RegisteredAt: time.Date(2025, 2, 3, 23, 3, 15, 0, time.UTC),
		},
		User{
			ID:           "123",
			Name:         "Alice",
			RegisteredAt: time.Date(2024, 12, 19, 5, 45, 50, 0, jst),
		},
	)

	fmt.Println(s)

}
Output:
  akashi_test.User{
    ID: "123",
    Name: "Alice",
-   RegisteredAt: time.Time("2025-02-03 23:03:15 +0000 UTC"),
+   RegisteredAt: time.Time("2024-12-19 05:45:50 +0900 JST"),
  }
Example (Slice)
package main

import (
	"fmt"

	"github.com/seiyab/akashi"
)

func main() {
	s := akashi.DiffString(
		[]string{"a", "b", "c", "d"},
		[]string{"a", "c", "d", "e"},
	)

	fmt.Println(s)

}
Output:
  []string{
    "a",
-   "b",
    "c",
    "d",
+   "e",
  }

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultColorProfile = ColorProfile{
	Left:    "\x1b[31m",
	Right:   "\x1b[32m",
	Neutral: "",
	Reset:   "\x1b[0m",
}

Functions

func DiffString

func DiffString(x, y interface{}, options ...Option) string

DiffString returns a string that represents the difference between x and y.

Types

type ColorProfile added in v0.0.3

type ColorProfile = doc.ColorProfile

type Option

type Option func(*differ) *differ

Option is an option for DiffString.

func WithColor added in v0.0.3

func WithColor(profile ...ColorProfile) Option

func WithFormat

func WithFormat(fn interface{}) Option

WithFormat sets a function to format a value.

Example
package main

import (
	"fmt"
	"time"

	"github.com/seiyab/akashi"
)

func main() {
	s := akashi.DiffString(
		time.Date(2025, 2, 3, 23, 3, 15, 0, time.UTC),
		time.Date(2024, 12, 19, 5, 45, 50, 0, time.UTC),
		akashi.WithFormat(
			func(t time.Time) string {
				return t.Format(time.RFC3339)
			},
		),
	)

	fmt.Println(s)

}
Output:
- time.Time("2025-02-03T23:03:15Z")
+ time.Time("2024-12-19T05:45:50Z")

func WithReflectEqual

func WithReflectEqual(fn func(v1, v2 reflect.Value) bool) Option

WithReflectEqual sets a function to compare reflect.Value.

Directories

Path Synopsis
internal
doc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL