refaklet

package module
v0.0.0-...-6ddbdac Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 8 Imported by: 0

README

refaklet

fake reflect for go

Repr

show a go var as it self repr type.

package main

import (
	"fmt"

	"github.com/alingse/refaklet"
)

type DemoValue struct {
	A int
	B *int
	C string
	D []byte
	E []any
}

var demoValue = &DemoValue{
	A: 1,
	B: ptr(int(100)),
	C: "hello",
	D: []byte{1, 2, 3},
	E: []interface{}{
		byte(10),
		int64(11),
	},
}

func ptr[T any](v T) *T { return &v }

var repr_ = `&main.DemoValue{
	A:	1,
	B:	ptr(int(100)),
	C:	"hello",
	D:	[]byte{0x1, 0x2, 0x3},
	E:	[]any{
		uint8(0xa),
		int64(11),
	},
}

func ptr[T any](v T) *T { return &v }`

func main() {
	v := refaklet.ValueOf(demoValue)
	repr := v.Repr()
	fmt.Println(repr == repr_)
}

LICENSE

some code copy and modified from https://github.com/kr/pretty with MIT license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValueOf

func ValueOf(v any) refakletValue

Types

This section is empty.

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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