Giter Club home page Giter Club logo

go-pprint's Introduction

go-pprint

一个能够格式化输出的golang小工具(pretty print)

为了方便开发和调试,能够清晰看到结构体的值:

package main

import (
	"time"
	"github.com/timest/go-pprint"
)

type Policy struct {
	Allow string
	Deny  string
}

type Host struct {
	ip     string
	alias  []string
	policy Policy
}
type Redis struct {
	name string // lower-case
	port uint   // lower-case
	host Host
}

type Web struct {
	Host    string
	port    int32 // lower-case
	Timeout time.Duration
	Rate    float32
	Score   []float32
	IP      []string
	MySQL struct {
		Name string
		port int64 // lower-case
	}
	redis *Redis
}

func main() {
	w := &Web{
		Host:    "web host",
		port:    1234,
		Timeout: 5 * time.Second,
		Rate:    0.32,
		Score:   []float32{1.1, 2.2, 3.3},
		IP:      []string{"192.168.1.1", "127.0.0.1", "localhost"},
		MySQL: struct {
			Name string
			port int64
		}{Name: "mysqldb", port: 3306},
		redis: &Redis{"rdb", 6379, Host{"adf", []string{"alias1", "alias2"}, Policy{"allow policy", "deny policy"}}},
	}
	// 调用pprint 格式化输出
	pprint.Format(w)
}

输出结果:

image

go-pprint's People

Contributors

dqinyuan avatar timest avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.