Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

The devil is in the (logging) details

When using structured logging, it is very easy to get carried away and try to stuff as much information as possible into the key-value pairs. Unfortunately, this can often prove to be dangerous security-wise! Take a look at the following code snippet, which retrieves a user's data from a URL they have provided to us:

func fetchUserData(url *url.URL) (*user.Data, error) {
    tick := time.Now()
    res, err := http.Get(url.String())
    if err != nil {
        return nil, err
    }
    defer func() { _ = res.Body.Close() }()

    logrus.WithFields(logrus.Fields{
        "url":  url,
        "time": time.Since(tick).String(),
    }).Info("retrieved user data")

    // omitted: read and unmarshal user data
}

Whenever we succeed in fetching the data, we log an

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content