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”.

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
New
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New

Sub Categories: