Improving the code from the official Go RESTful API tutorial

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • go

    The Go programming language

    I suspect it's because Go's general philosophy is that it's better to be verbose and explicit (than terse and magical). Probably falls under "clear is better than clever" from Rob Pike's Go Proverbs: http://go-proverbs.github.io/

    I think if this feature was added, it would not be with struct tags, but with an Encoder.SetFieldTransform(json.SnakeCase) or similar setting.

    That might be quite a nice feature, actually. You could provide your own function to transform names when marshaling, and for unmarshaling it would strip punctuation and match case insensitively (because it's hard to do the reverse transform, for example should user_id go to UserId or UserID, and if the latter, how does the transform know?).

    In any case, it seems like an issue was opened proposing something like that a couple of years ago (https://github.com/golang/go/issues/23027), and Russ Cox responded that the JSON package is basically done, but you could either fork it and add the feature, or use a tool that modifies struct tags like https://github.com/fatih/gomodifytags

  • gomodifytags

    Go tool to modify struct field tags

    I suspect it's because Go's general philosophy is that it's better to be verbose and explicit (than terse and magical). Probably falls under "clear is better than clever" from Rob Pike's Go Proverbs: http://go-proverbs.github.io/

    I think if this feature was added, it would not be with struct tags, but with an Encoder.SetFieldTransform(json.SnakeCase) or similar setting.

    That might be quite a nice feature, actually. You could provide your own function to transform names when marshaling, and for unmarshaling it would strip punctuation and match case insensitively (because it's hard to do the reverse transform, for example should user_id go to UserId or UserID, and if the latter, how does the transform know?).

    In any case, it seems like an issue was opened proposing something like that a couple of years ago (https://github.com/golang/go/issues/23027), and Russ Cox responded that the JSON package is basically done, but you could either fork it and add the feature, or use a tool that modifies struct tags like https://github.com/fatih/gomodifytags

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts