Mix XFMT

可以打印结构体嵌套指针地址内部数据的格式化库

Formatting library that can print the internal data of the nested pointer address of the struct

Github

Overview

fmt

Installation

  • 安装
go get -u github.com/mix-go/xfmt

Usage

fmtSprintf(format string, args ...interface{}) stringSprint(args ...interface{}) stringSprintln(args ...interface{}) stringPrintf(format string, args ...interface{})Print(args ...interface{})Println(args ...interface{})Tag
type Foo struct {
    Bar *Bar `xfmt:"-"`
}
  • 使用

包含指针的结构体

type Level3 struct {
    Name string
}

type Level2 struct {
    Level3 *Level3 `xfmt:"-"`
    Name   string
}

type Level1 struct {
    Name     string
    Level2   *Level2
    Level2_1 *Level2
}

创建变量

l3 := Level3{Name: "Level3"}
l2 := Level2{Name: "Level2", Level3: &l3}
l1 := Level1{Name: "Level1", Level2: &l2, Level2_1: &l2}

打印对比

fmt
fmt.Println(fmt.Sprintf("%+v", l1))
{Name:Level1 Level2:0xc00009c500 Level2_1:0xc00009c500}
xfmt
fmt.Println(xfmt.Sprintf("%+v", l1))
{Name:Level1 Level2:0xc00009c500:&{Level3:0xc00007f030 Name:Level2} Level2_1:0xc00009c500}

License