raul

raul

Distributed Services with Go: Chapter 1 Suggestions

Hi Travis! Thank you for the cool book! :slight_smile:

I made a list of issues and thought I could post them chapter by chapter. I’m reviewing distributed-services-with-go_B4.0.pdf. Please let me know if you’d prefer me to post them issue by issue instead. That’s going to take longer…

Chapter 1. Let’s Go

Page footer includes links to:
+ report erratum: http://pragprog.com/titles/tjgo/errata/add
+ discuss: http://forums.pragprog.com/forums/tjgo
+ Are both of these outdated?

So you can build a simple commit log with a slice.

  • (Before reading up on Go) What’s a slice?
  • For a Go newbie, maybe it’s better to call it ‘Go slice’? But I guess the book title does say ‘with Go’ :slight_smile:

Set Up the Project
$ mkdir proglog
$ cd proglog
$ go mod init github.com/travisjeffery/proglog

  • This creates a go.mod in the top-level proglog folder
  • But when I checkout the github project to compare, the go.mod file is in proglog/LetsGo. Thought I’d mention in case things aren’t as intended.

Create a internal/server directory tree in the root of your project and put the following code under the server directory in a file called log.go:

  • Create a → Create ‘an’
  • LetsGo in the code path is not introduced anywhere?
  • Does it need to be there, or should it be ‘proglog’ instead?
  • Personally, I think Chapter_1/ would make it clearer if that were the intention.

LetsGo/internal/server/log.go

  • Trying to copy the code from the pdf didn’t work - all kinds of extra formatting was turning up on the Mac? Is there some option I need to be enabling? I finally copied in one line at a time because even copying one method at a time ran into issues.
  • Clicking on the link takes to the code in the browser! Hadn’t known that, maybe you could mention it in the text? That was a life saver in terms of helping with copying in code!
  1. Unmarshal the request’s JSON body into a struct.
  • (Before reading up on Go) Does struct mean a record here? What’s a struct?
  • For a Go newbie, maybe it’s better to call it ‘Go struct’?

so the user just needs to call ListenAndServe() to

  • What’s ListenAndServe()? Sorry didn’t understand this

$ go run main.go

func main() {

curl -X POST localhost:8080 -d
‘{“record”: {“value”: “TGV0J3MgR28gIzEK”}}’

  • That worked!
  • Would it be a good idea to include the output as well, so that people can cross-check whether things look good?
  • {“offset”:0}

curl -X GET localhost:8080 -d ‘{“offset”: 0}’

  • Would it be a good idea to include the output folks should expect?
  • {“record”:{“value”:“TGV0J3MgR28gIzEK”,“offset”:0}}

Would it be a good idea to include a section on setting up GoLand that would help with debugging later on, even in a later chapter?

  • It took me a while to figure out what to point GOROOT at, with goenv. I finally pointed it at the go version in ~/.goenv/versions/ that my go was coming from and am not sure whether that’s the way to go but it seems to work for now.

Most Liked

rsippl

rsippl

The mutex makes sure you don’t read from the log while writing to it. You could have n concurrent readers without needing a mutex, if only you were sure no one is writing to it. Actually, this is a scenario for sync.RWMutex. Its docs explain it well: “The lock can be held by an arbitrary number of readers or a single writer”.

Popular Prag Prog topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1016 16836 371
New
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
Or looking forward to? :nerd_face:
New
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
New

Latest in PragProg

View all threads ❯