gotree

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 2 Imported by: 13

README

gotree

gotree is a library to output tree like string slices in your Go program.

Its use is focused on logging out settings in a 💅 way.

Usage

package main

import (
    "fmt"
    "strings"

    "github.com/qdm12/gotree"
)

func main() {
    settings := Settings{
        LogLevel: 2,
        Server: ServerSettings{
            Address: ":8000",
            Debug:   true,
        },
    }
    fmt.Println(settings)
}

type Settings struct {
    LogLevel int
    Server   ServerSettings
}

type ServerSettings struct {
    Address string
    Debug   bool
}

func (s Settings) String() string {
    return strings.Join(s.toNode().ToLines(), "\n")
}

func (s Settings) toNode() *gotree.Node {
    node := gotree.New("Settings:")
    node.Appendf("Log level: %d", s.LogLevel)
    node.AppendNode(s.Server.toNode())
    return node
}

func (s ServerSettings) toNode() *gotree.Node {
    node := gotree.New("Server settings:")
    node.Appendf("Address: %s", s.Address)
    node.Appendf("Debug: %t", s.Debug)
    return node
}

Will print out

Settings:
├── Log level: 2
└── Server settings:
    ├── Address: :8000
    └── Debug: true

See the examples directory for more cases.

Setup

go get github.com/qdm12/gotree

Safety to use

  • Full unit test coverage
  • Full integration test coverage
  • Linting with golangci-lint with most of its linters enabled
  • In use by the following Go projects:

Bug and feature request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

func New

func New(format string, args ...interface{}) *Node

func (*Node) AppendNode

func (n *Node) AppendNode(node *Node)

func (*Node) Appendf

func (n *Node) Appendf(format string, args ...interface{}) (newNode *Node)

func (*Node) String

func (n *Node) String() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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