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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
refaklet command
examples
show-repr command

Jump to

Keyboard shortcuts

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