697

How can I print (to the console) the Id, Title, Name, etc. of this struct in Golang?

type Project struct {
    Id      int64   `json:"project_id"`
    Title   string  `json:"title"`
    Name    string  `json:"name"`
    Data    Data    `json:"data"`
    Commits Commits `json:"commits"`
}
John Smith
  • 7,243
  • 6
  • 49
  • 61
fnr
  • 9,007
  • 5
  • 17
  • 16

31 Answers31

1173

To print the name of the fields in a struct:

fmt.Printf("%+v\n", yourProject)

From the fmt package:

when printing structs, the plus flag (%+v) adds field names

That supposes you have an instance of Project (in 'yourProject')

The article JSON and Go will give more details on how to retrieve the values from a JSON struct.


This Go by example page provides another technique:

type Response2 struct {
  Page   int      `json:"page"`
  Fruits []string `json:"fruits"`
}

res2D := &Response2{
    Page:   1,
    Fruits: []string{"apple", "peach", "pear"}}
res2B, _ := json.Marshal(res2D)
fmt.Println(string(res2B))

That would print:

{"page":1,"fruits":["apple","peach","pear"]}

If you don't have any instance, then you need to use reflection to display the name of the field of a given struct, as in this example.

type T struct {
    A int
    B string
}

t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()

for i := 0; i < s.NumField(); i++ {
    f := s.Field(i)
    fmt.Printf("%d: %s %s = %v\n", i,
        typeOfT.Field(i).Name, f.Type(), f.Interface())
}
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Thanks for your answer but there is one more thing. My JSON files are related to an API... therefor I dont want to set the Id or Name, I just want to get it over the API and print it in console. How can I do that? – fnr Jul 01 '14 at 14:13
  • 7
    @fnr If you have a JSON document, you would need to unmarshall it, before being able to print its field. – VonC Jul 01 '14 at 14:16
  • 6
    Upvoted! My one complaint is the %+v command does not pretty print it! I am still happy with the efficiency of this line. – Shadoninja Dec 06 '16 at 16:26
  • It really is too bad that the language doesn't have a feature to pretty print out of the box. You'd think that most people would find something like that useful for debugging. – Landon Poch Aug 21 '18 at 05:19
  • 3
    Need to do import "encoding/json" for the json marshalling technique, – Jim Hoagland Oct 18 '18 at 20:29
  • also you can use reflection to printing out your data into any format that you want – Manouchehr Rasouli Feb 07 '20 at 17:48
  • 1
    @ManouchehrRasouli I agree. I believe that is what https://github.com/davecgh/go-spew is doing (mentioned in the answer below) – VonC Feb 07 '20 at 17:52
  • 4
    Note that .Printf("%+v\n") also works with the "log" package – Ariel Monaco Feb 17 '20 at 18:29
  • @ArielMonaco Yes, https://golang.org/pkg/log/#Printf uses the same format. – VonC Feb 18 '20 at 07:11
  • 1
    Just a note, this works nicely with pointers as well. It won't print out the address, but it will add a `&` in front of your output. – Marko Jan 10 '23 at 09:45
209

I want to recommend go-spew, which according to their github "Implements a deep pretty printer for Go data structures to aid in debugging"

go get -u github.com/davecgh/go-spew/spew

usage example:

package main

import (
    "github.com/davecgh/go-spew/spew"
)

type Project struct {
    Id      int64  `json:"project_id"`
    Title   string `json:"title"`
    Name    string `json:"name"`
    Data    string `json:"data"`
    Commits string `json:"commits"`
}

func main() {

    o := Project{Name: "hello", Title: "world"}
    spew.Dump(o)
}

output:

(main.Project) {
 Id: (int64) 0,
 Title: (string) (len=5) "world",
 Name: (string) (len=5) "hello",
 Data: (string) "",
 Commits: (string) ""
}
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Martin Olika
  • 2,223
  • 1
  • 12
  • 3
  • 6
    you could add the dereference feature that go-spew has. It allows you to print the value of the struct where a pointer is referencing and not the pointer itsel –  Jan 30 '17 at 20:49
  • 1
    The big pro with use spew is that the output is already well formatted so you can easily check all the object properties. – COil Sep 16 '19 at 10:40
197

my 2cents would be to use json.MarshalIndent -- surprised this isn't suggested, as it is the most straightforward. for example:

func prettyPrint(i interface{}) string {
    s, _ := json.MarshalIndent(i, "", "\t")
    return string(s)
}

no external deps and results in nicely formatted output.

mad.meesh
  • 2,558
  • 1
  • 13
  • 20
  • 3
    Exactly what I was looking for. Easy pretty printing with reuse of built in json library. – AdmiralThrawn Jun 03 '19 at 17:47
  • 2
    Unless one needs to print field type and length (Spew is great for that), this solution is just the best as Pointers are also properly printed! – Christophe Vidal Sep 16 '19 at 20:19
  • Short and sweet. You can replace `"\t"` with `" "` if you want space indenting instead – Dana Woodman Oct 10 '19 at 16:11
  • 7
    Of note, [`Marshal()`](https://golang.org/pkg/encoding/json/#Marshal) only serializes the exported fields of a struct -- it's perfect for maps though. – Brent Bradburn Nov 15 '19 at 16:20
  • 1
    The best answer. – Hu Xixi Aug 31 '22 at 06:55
  • Definitely not a viable solution as non-exported fields AND exported fields with ignored JSON tag (i.e. json:"-") will not be included. – GoForth Mar 19 '23 at 19:28
  • @GoForth define "viable" -- your comment is dismissive, assumes too much and in general not helpful; the OP did not include any constraints in his question: he provided a struct (all exported and tagged fields) and wanted to know how to print it. exactly how is the simple proposed code `definitely not a viable solution` to their query? – mad.meesh Mar 19 '23 at 19:50
  • @mad.meesh By not viable I meant that while it works for OP's struct as all fields are exported and mapped to JSON, this solution is not a generally viable solution for all structs. – GoForth Mar 19 '23 at 20:07
  • @GoForth well.. couple things. first, again, your comment isn't helping nor pertaining to the OP. and second, we'll just have to -- respectively -- agree to disagree. i _do_ think this solution is viable _in the general case_. where i will agree with you is that there are _some_ cases where this solution has to be _modified_. but _in general_ it gets you there. – mad.meesh Mar 20 '23 at 20:50
49

I think it would be better to implement a custom stringer if you want some kind of formatted output of a struct

for example

package main

    import "fmt"

    type Project struct {
        Id int64 `json:"project_id"`
        Title string `json:"title"`
        Name string `json:"name"`
    }

    func (p Project) String() string {
        return fmt.Sprintf("{Id:%d, Title:%s, Name:%s}", p.Id, p.Title, p.Name)
    }

    func main() {
        o := Project{Id: 4, Name: "hello", Title: "world"}
        fmt.Printf("%+v\n", o)
    }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Vivek Maru
  • 8,347
  • 1
  • 24
  • 34
27
p = Project{...}
fmt.Printf("%+v", p)
fmt.Printf("%#v", p) //with type
cokeboL
  • 287
  • 3
  • 2
  • 2
    `fmt.Printf(%#v, p)` , throws me `main.struct` with `struct type` what is the difference between `"%#v"` and `"%+v"` @cokebol – muthukumar selvaraj Jan 23 '18 at 13:26
  • "%+v" : This will give you the un-marshalled value along with their field-names. "%#v" : This will give the values along with their type/signatures. For eg: p := Project{Id: 4, Name: "hello", Title: "world"} output for "%+v": {Id:4 Title:world Name:hello} output for "%#v": main.Project{Id:4, Title:"world", Name:"hello"} – Gaurav Jan 08 '22 at 08:03
27

Alternatively, try using this function PrettyPrint()

// print the contents of the obj
func PrettyPrint(data interface{}) {
    var p []byte
    //    var err := error
    p, err := json.MarshalIndent(data, "", "\t")
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Printf("%s \n", p)
}

In order to use this you do not need any additional packages with the exception of fmt and encoding/json, just a reference, pointer to, or literal of the struct you have created.

To use just take your struct, initialize it in main or whatever package you are in and pass it into PrettyPrint().

type Prefix struct {
    Network string
    Mask    int
}

func valueStruct() {
    // struct as a value
    var nw Prefix
    nw.Network = "10.1.1.0"
    nw.Mask = 24
    fmt.Println("### struct as a pointer ###")
    PrettyPrint(&nw)
}

It's output would be

### struct as a pointer ###
{
    "Network": "10.1.1.0",
    "Mask": 24
} 

Play around with the code here.

Erik Toor
  • 522
  • 6
  • 6
16

It is very convenient to use package fmt to output:

fmt.Printf("%+v \n", yourProject)

if you want to see the full type of the sturct, you can use # replace + :

fmt.Printf("%#v \n", yourProject) 
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Kepner Wu
  • 184
  • 1
  • 3
16

I suggest u use fmt.Printf("%#v\n", s) , It will print golang type at the same time

package main

import (
    "fmt"
    "testing"
)

type student struct {
    id   int32
    name string
}

type Project struct {
    Id      int64   `json:"project_id"`
    Title   string  `json:"title"`
    Name    string  `json:"name"`
}

func TestPrint(t *testing.T) {
    s := Project{1, "title","jack"}
    fmt.Printf("%+v\n", s)
    fmt.Printf("%#v\n", s)
}

result:

{Id:1 Title:title Name:jack}
main.Project{Id:1, Title:"title", Name:"jack"}
刘孟德
  • 171
  • 1
  • 8
12

I recommend to use Pretty Printer Library. In that you can print any struct very easily.

  1. Install Library

    https://github.com/kr/pretty

or

go get github.com/kr/pretty

Now do like this in your code

package main

import (
fmt
github.com/kr/pretty
)

func main(){

type Project struct {
    Id int64 `json:"project_id"`
    Title string `json:"title"`
    Name string `json:"name"`
    Data Data `json:"data"`
    Commits Commits `json:"commits"`
}

fmt.Printf("%# v", pretty.Formatter(Project)) //It will print all struct details

fmt.Printf("%# v", pretty.Formatter(Project.Id)) //It will print component one by one.

}

Also you can get difference between component through this library and so more. You can also have a look on library Docs here.

amku91
  • 1,010
  • 11
  • 21
10

I like litter.

From their readme:

type Person struct {
  Name   string
  Age    int
  Parent *Person
}

litter.Dump(Person{
  Name:   "Bob",
  Age:    20,
  Parent: &Person{
    Name: "Jane",
    Age:  50,
  },
})

Sdump is pretty handy in tests:

func TestSearch(t *testing.T) {
  result := DoSearch()

  actual := litterOpts.Sdump(result)
  expected, err := ioutil.ReadFile("testdata.txt")
  if err != nil {
    // First run, write test data since it doesn't exist
        if !os.IsNotExist(err) {
      t.Error(err)
    }
    ioutil.Write("testdata.txt", actual, 0644)
    actual = expected
  }
  if expected != actual {
    t.Errorf("Expected %s, got %s", expected, actual)
  }
}
qed
  • 22,298
  • 21
  • 125
  • 196
8

To print the struct as JSON:

fmt.Printf("%#v\n", yourProject)

Also possible with (as it was mentioned above):

fmt.Printf("%+v\n", yourProject)

But the second option prints string values without "" so it is harder to read.

Ivan Gerasimenko
  • 2,381
  • 3
  • 30
  • 46
6

Sometimes, it might be handy to print the struct as valid Go code (the go/ast equivalent). For this purpose, https://github.com/hexops/valast does a great job:

package main

import (
    "fmt"

    "github.com/hexops/valast"
)

type ProjectData struct {
    Title   string `json:"title"`
    Name    string `json:"name"`
    Data    string `json:"data"`
    Commits string `json:"commits"`
}

type Project struct {
    Id   int64        `json:"project_id"`
    Data *ProjectData `json:"data"`
}

func main() {
    p := Project{
        Id: 1,
        Data: &ProjectData{
            Title:   "Test",
            Name:    "Mihai",
            Data:    "Some data",
            Commits: "Test Message",
        },
    }
    fmt.Println(valast.String(p))
}

Output:

go run main.go 
Project{Id: 1, Data: &ProjectData{
        Title:   "Test",
        Name:    "Mihai",
        Data:    "Some data",
        Commits: "Test Message",
}}
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
  • Sadly, it looks like `go-spew` hasn't received any updates in a long time. I believe it might have been abandoned. For now, it's still functional though. – Mihai Todor Aug 16 '21 at 19:04
6

You can do the json mashal first and print it as a string. There you can see it the whole struct value completely.

package main

import "fmt"
import "json"

type Project struct {
    Id int64 `json:"project_id"`
    Title string `json:"title"`
    Name string `json:"name"`
}

func main() {
    o := Project{Id: 4, Name: "hello", Title: "world"}
    om, _ := json.marshal(o)
    log.Printf("%s\n", string(om))
}
Brandon Heng
  • 117
  • 2
  • 8
5

When you have more complex structures, you might need to convert to JSON before printing:

// Convert structs to JSON.
data, err := json.Marshal(myComplexStruct)
fmt.Printf("%s\n", data)

Source: https://gist.github.com/tetsuok/4942960

Cassio
  • 1,347
  • 13
  • 15
3

Visit here to see the complete code. Here you will also find a link for an online terminal where the complete code can be run and the program represents how to extract structure's information(field's name their type & value). Below is the program snippet that only prints the field names.

package main

import "fmt"
import "reflect"

func main() {
    type Book struct {
        Id    int
        Name  string
        Title string
    }

    book := Book{1, "Let us C", "Enjoy programming with practice"}
    e := reflect.ValueOf(&book).Elem()

    for i := 0; i < e.NumField(); i++ {
        fieldName := e.Type().Field(i).Name
        fmt.Printf("%v\n", fieldName)
    }
}

/*
Id
Name
Title
*/
hygull
  • 8,464
  • 2
  • 43
  • 52
1

There's also go-render, which handles pointer recursion and lots of key sorting for string and int maps.

Installation:

go get github.com/luci/go-render/render

Example:

type customType int
type testStruct struct {
        S string
        V *map[string]int
        I interface{}
}

a := testStruct{
        S: "hello",
        V: &map[string]int{"foo": 0, "bar": 1},
        I: customType(42),
}

fmt.Println("Render test:")
fmt.Printf("fmt.Printf:    %#v\n", a)))
fmt.Printf("render.Render: %s\n", Render(a))

Which prints:

fmt.Printf:    render.testStruct{S:"hello", V:(*map[string]int)(0x600dd065), I:42}
render.Render: render.testStruct{S:"hello", V:(*map[string]int){"bar":1, "foo":0}, I:render.customType(42)}
Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50
1

Maybe this shouldn't be applied for production requests but if you are on debugging mode I suggest you follow the below approach.

marshalledText, _ := json.MarshalIndent(inputStruct, "", " ")
fmt.Println(string(marshalledText))

This results in formatting the data in json format with increased readability.

mourya venkat
  • 267
  • 3
  • 10
1

i suggest to use json.Unmarshal() i try to print the id with this hope its helpfull:

var jsonString = `{"Id": 1, "Title": "the title", "Name": "the name","Data": "the data","Commits" : "the commits"}`
var jsonData = []byte(jsonString)

var data Project

var err = json.Unmarshal(jsonData, &data)
if err != nil {
    fmt.Println(err.Error())
    return
}

fmt.Println("Id :", data.Id)
1

Here's an example demonstrating the use of format specifiers %d, %t, and %s for each built-in type in Go like: int, string, bool, struct, and interface.

package main

import "fmt"

// Define a struct
type Person struct {
    Name string
    Age  int
}

// Define an interface
type Describer interface {
    Describe() string
}

// Implement the Describer interface for Person
func (p Person) Describe() string {
    return fmt.Sprintf("Name: %s, Age: %d", p.Name, p.Age)
}

func main() {
    // Integer
    intVar := 42
    fmt.Printf("Integer %%d: %d\n", intVar)

    // Boolean
    boolVar := true
    fmt.Printf("Boolean %%t: %t\n", boolVar)

    // String
    strVar := "Hello, Go!"
    fmt.Printf("String %%s: %s\n", strVar)

    // Struct
    person := Person{Name: "Alice", Age: 30}
    fmt.Printf("Struct %%+v: %+v\n", person)

    // Interface
    var describer Describer
    describer = person
    fmt.Printf("Interface %%s: %s\n", describer.Describe())
}

In this example, each type is printed using the specified format specifiers.

%d is for integers

%t` is for booleans

%s` is for strings

%+v` is for structs, showing field names along with values

I hope it would be helpful for you. For more details, you can read this blog Exploring Built-in Types in Go

Md Kamruzzaman
  • 346
  • 1
  • 8
0
fmt.Printf("%+v\n", project)

This is the basic way of printing the details

0example.com
  • 317
  • 2
  • 4
0

You don't even need the verb. This dumps everything inside of data:

fmt.Println(data)
PJ Brunet
  • 3,615
  • 40
  • 37
0

Sharing an easy to follow example here for accessing just the Id, Title, Name, Data and Commits independently (presuming Data and Commits are meant to be JSON):

package main

import (
  "fmt"
  "encoding/json"
)

type Project struct {
    Id      int64   `json:"project_id"`
    Title   string  `json:"title"`
    Name    string  `json:"name"`
    Data    json.RawMessage `json:"data"`
    Commits json.RawMessage `json:"commits"`
}

func main() {
  
    jsonDataStr := `{"key1":"value1", "key2":"value2"}`
    jsonData := []byte(jsonDataStr)
  
    jsonCommitStr := `{"commit1":"value1", "commit2":"value2"}`
    jsonCommits := []byte(jsonCommitStr)

    myProject := Project {
      Id: 101, 
      Title: "Trello", 
      Name: "Dashboard", 
      Data: jsonData,
      Commits: jsonCommits,
    }
  
    fmt.Println("ID: ", myProject.Id)
    fmt.Println("Title: ", myProject.Title)
    fmt.Println("Name: ", myProject.Name)

    // Unmarshall and print the JSON keys and values
    var dataMap map[string]string
    err := json.Unmarshal(myProject.Data, &dataMap)
    if err != nil {
      fmt.Println("Error decoding Data:", err)
    } else {
      fmt.Println("Data: ", dataMap)
    }
    
    var commitsMap map[string]string
    err = json.Unmarshal(myProject.Commits, &commitsMap)
    if err != nil {
      fmt.Println("Error decoding Commits:", err)
    } else {
      fmt.Println("Commits: ", commitsMap)
    }
}

You can copy and paste this into https://replit.com/languages/go and it will print out the output as:

ID:  101
Title:  Trello
Name:  Dashboard
Data:  map[key1:value1 key2:value2]
Commits:  map[commit1:value1 commit2:value2]
0

There are three format specifiers for printing a struct.

%v – It will print only values. The field name will not be printed. This is the default way of printing a struct when using Println

%+v – It will print both field and value.

%#v – It will print the struct, also both field name and value

Mainly we want to print it in error or info logs. A hands-on example seems to be perfect in understanding the same.

package main

import (
    "fmt"
)

type employee struct {
    Name string
    Age  int
}

func main() {
    sampleErr := "database connection issue"

    err := fmt.Errorf("Err is: %s", sampleErr)
    fmt.Println(err)

    port := 8080

    err = fmt.Errorf("Err is: %s to port %d", sampleErr, port)
    fmt.Println(err)

    e := employee{
        Name: "John",
    }

    err = fmt.Errorf("Employee not found. Details %v", e)
    fmt.Println(err)
    err = fmt.Errorf("Employee not found. Details %+v", e)
    fmt.Println(err)
    err = fmt.Errorf("Employee not found. Details %#v", e)
    fmt.Println(err)
}

Output -

Err is: database connection issue
Err is: database connection issue to port 8080
Employee not found. Details {John 0}
Employee not found. Details {Name:John Age:0}
Employee not found. Details main.employee{Name:"John", Age:0}
Dipesh Yadav
  • 2,353
  • 1
  • 14
  • 9
-1

Without using external libraries and with new line after each field:

log.Println(
            strings.Replace(
                fmt.Sprintf("%#v", post), ", ", "\n", -1))
-1

very simple I don't have the structure of Data and Commits So I changed the

package main

import (
    "fmt"
)

type Project struct {
    Id      int64   `json:"project_id"`
    Title   string  `json:"title"`
    Name    string  `json:"name"`
    Data    string  `json:"data"`
    Commits string  `json:"commits"`
}

func main() {
    p := Project{
    1,
    "First",
    "Ankit",
    "your data",
    "Commit message",
    }
    fmt.Println(p)
}

For learning you can take help from here : https://gobyexample.com/structs

-1

If you want to write in a log file, as I was searching previously. Then you should use:

log.Infof("Information %+v", structure)

Note:: This will not work with log.Info or log.Debug. In this case, "%v" will get printed, and all the values of the structure will be printed without printing the key/variable name.

Ayush
  • 373
  • 4
  • 12
-1

A lot of answers for a simple question. I might as well throw my hat in the ring.

package main

import "fmt"

type Project struct {
    Id    int64  `json:"project_id"`
    Title string `json:"title"`
    Name  string `json:"name"`
    //Data    Data    `json:"data"`
    //Commits Commits `json:"commits"`
}

var (
    Testy Project
)

func dump_project(foo Project) {
    fmt.Println("== Dump Project Struct ====")
    fmt.Printf("Id: %d\n", foo.Id)
    fmt.Println("Title: ", foo.Title)
    fmt.Printf("Name: %v\n", foo.Name)
}

func main() {
    fmt.Println("hello from go")
    Testy.Id = 3
    Testy.Title = "yo"
    Testy.Name = "my name"
    fmt.Println(Testy)
    dump_project(Testy)
}

The output of the various print methods

hello from go
{3 yo my name}
== Dump Project Struct ====
Id: 3
Title:  yo
Name: my name
netskink
  • 4,033
  • 2
  • 34
  • 46
-2
    type Response struct {
        UserId int    `json:"userId"`
        Id     int    `json:"id"`
        Title  string `json:"title"`
        Body   string `json:"body"`
    }

    func PostsGet() gin.HandlerFunc {
        return func(c *gin.Context) {
            xs, err := http.Get("https://jsonplaceholder.typicode.com/posts")
            if err != nil {
                log.Println("The HTTP request failed with error: ", err)
            }
            data, _ := ioutil.ReadAll(xs`enter code here`.Body)


            // this will print the struct in console            
            fmt.Println(string(data))


            // this is to send as response for the API
            bytes := []byte(string(data))
            var res []Response
            json.Unmarshal(bytes, &res)

            c.JSON(http.StatusOK, res)
        }
    }
-3

Another way is, create a func called toString that takes struct, format the fields as you wish.

import (
    "fmt"
)

type T struct {
    x, y string
}

func (r T) toString() string {
    return "Formate as u need :" + r.x + r.y
}

func main() {
    r1 := T{"csa", "ac"}
    fmt.Println("toStringed : ", r1.toString())
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
pschilakanti
  • 903
  • 6
  • 7
  • 4
    Or you could implement the `Stringer` interface. It would look something like this: ```func (t T) String() string { return fmt.Sprintf("SomeT{TID: %d, TField: %d, SomeTField: %s, SomeAnotherField: %s}", t.ID, t.Field, t.SomeTField, t.SomeAnotherField) }``` – rbo13 Jan 01 '19 at 14:25
-7

Most of these packages are relying on the reflect package to make such things possible.

enter image description here

fmt.Sprintf() is using -> func (p *pp) printArg(arg interface{}, verb rune) of standard lib

Go to line 638 -> https://golang.org/src/fmt/print.go

Reflection:

https://golang.org/pkg/reflect/

Example code:

https://github.com/donutloop/toolkit/blob/master/debugutil/prettysprint.go

Donutloop
  • 427
  • 3
  • 15
-10
fmt.Println("%+v", structure variable)

A better way to do this would be to create a global constant for the string "%+v" in a package called "commons"(maybe) and use it everywhere in your code

//In commons package
const STRUCTURE_DATA_FMT = "%+v"

//In your code everywhere
fmt.Println(commons.STRUCTURE_DATA_FMT, structure variable)
  • 8
    Politely, people have down-voted this because the `Println` function doesn't accept a format string argument. You say a global constant is better but haven't justified why it is better than the marked answer. You have created a nonstandard label for a well known format string. The label is much longer, harder to remember and no-one else who works on your code would use it. It uses both ALL_CAPS and an underscore which every golang linter will complain about. The convention is `mixedCaps` https://golang.org/doc/effective_go.html#mixed-caps Probably best to remove this answer. – Davos Apr 09 '19 at 15:06