Skip to content

Eun/mapprint

Repository files navigation

mapprint

Actions Status Coverage Status PkgGoDev GoDoc go-report go1.15

Printf for maps and structs

go get github.com/Eun/mapprint
// prints `[14:01:08.005674] Database initialized'
mapprint.Printf("[%0H:%02m:%02s.%06ms] Database initialized", map[string]interface{}{
    "H": 14,
    "m": 1,
    "s": 8,
    "ms": 5674,
})

structs

type User struct {
    Name    string
    Balance int
}

// prints `Hello Joe, your balance is 104€!'
mapprint.Printf("Hello %Name, your balance is %Balance€!", User{
    Name:    "Joe",
    Balance: 104,
})

formating

// prints `Hello        Joe'
mapprint.Printf("Hello %10user!", map[string]string{
    "user": "Joe",
})

// prints `Hello Joe       '
mapprint.Printf("Hello %-10user!", map[string]string{
    "user": "Joe",
})

// prints `Hello    Joe    '
mapprint.Printf("Hello |-10user!", map[string]string{
    "user": "Joe",
})

// prints `Hello Joe, your balance is 0000104.00€!'
mapprint.Printf("Hello %Name, your balance is %010.2Balance€!", map[string]interface{}{
    "Name": "Joe",
    "Balance": 104,
})

// maybe something more exotic?
// prints `Hello Joe, your balance is ABAB104.00€!'
mapprint.Printf("Hello %Name, your balance is %AB10.2Balance€!", map[string]interface{}{
    "Name": "Joe",
    "Balance": 104,
})