Watch
1
0
Fork
You've already forked golang-github-qdm12-gotree
0
No description
  • Go 92.8%
  • Dockerfile 7.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Baumann 842d0737c7
Setting go compatibility in rules.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-06-25 07:19:50 +02:00
.devcontainer Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
.github Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
debian Setting go compatibility in rules. 2026-06-25 07:19:50 +02:00
examples/settings Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
.dockerignore Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
.golangci.yml Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
Dockerfile Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
endtoend_test.go Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
go.mod Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
go.sum Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
LICENSE Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
node.go Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
node_test.go Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00
README.md Adding upstream version 0.3.0. 2026-05-03 00:07:38 +02:00

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