Skip to content

Commit

Permalink
little fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
quii committed May 11, 2018
1 parent e09712b commit 13f90ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ If there's no link, it's not done yet! [why not contribute?](contributing.md)

Property based tests \(todo\)

### Standard lib essentials
### Build an application

* [HTTP server](http-server.md) - Learn how to TDD a web server
* [JSON and `IO` (WIP)](json.md) - Learn how to work with JSON, plus embedding types and some IO basics
* `time`
* Sorting
Now that you have hopefully digested the _Go Fundamentals_ section you have a solid grounding of a majority of Go's language features and how to write TDD.

This next section will involve building an application.

Each chapter will iterate on the previous one, expanding the applications functionality as our product owner dictates.

New concepts will be introduced to help facilitate writing great code but most of the new material will be learning what can be accomplished from Go's standard library.

- [HTTP server](http-server.md) - We will create an application which listens to HTTP requests and responds to them.
- [JSON (WIP)](json.md) - We will make our endpoints return JSON and explore how to do routing.
- [IO (WIP)](io.md) - We will persist and read our data from disk and we'll cover sorting data.

## Contributing

Expand Down
8 changes: 4 additions & 4 deletions app-intro.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Build an application

Now that you have hopefully digested the _Go Fundamentals_ section you have a solid grounding of a majority of Go's language features and how to write TDD.
Now that you have hopefully digested the _Go Fundamentals_ section you have a solid grounding of a majority of Go's language features and how to write TDD.

This next section will involve building an application.

Each chapter will iterate on the previous one, expanding the applications functionality as our product owner dictates.
Each chapter will iterate on the previous one, expanding the applications functionality as our product owner dictates.

New concepts will be introduced to help facilitate writing great code but most of the new material will be learning what can be accomplished from Go's standard library.

- [HTTP server](http-server.md) - We will create an application which listens to HTTP requests and responds to them.
- [JSON](json.md) - We will make our endpoints return JSON and explore how to do routing.
- [IO](io.md) - We will persist and read our data from disk and we'll cover sorting data.
- [JSON (WIP)](json.md) - We will make our endpoints return JSON and explore how to do routing.
- [IO (WIP)](io.md) - We will persist and read our data from disk and we'll cover sorting data.
26 changes: 12 additions & 14 deletions io.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func main() {

## Store the data

There are dozens of databases we could use for this but we're going to go for a very simple approach. We're going to store the data for this application in a file as JSON.
There are dozens of databases we could use for this but we're going to go for a very simple approach. We're going to store the data for this application in a file as JSON.

This keeps the data very portable and is relatively simple to implement.
This keeps the data very portable and is relatively simple to implement.

It wont scale especially well but given this is a prototype it'll be fine for now. If our circumstances change and it's no longer appropriate it'll be simple to swap it out for something different because of the `PlayerStore` abstraction we have used.

We will keep the `InMemoryPlayerStore` for now so that the integration tests keep passing as we develop our new store. Once we are confident our new implementation is sufficient to make the integration test pass we will swap it in and then delete `InMemoryPlayerStore`
We will keep the `InMemoryPlayerStore` for now so that the integration tests keep passing as we develop our new store. Once we are confident our new implementation is sufficient to make the integration test pass we will swap it in and then delete `InMemoryPlayerStore`.

## Write the test first

Expand Down Expand Up @@ -162,9 +162,7 @@ We're using `strings.NewReader` which will return us a `Reader`, which is what o
Let's define `FileSystemStore` in a new file

```go
type FileSystemStore struct {

}
type FileSystemStore struct {}
```

Try again
Expand Down Expand Up @@ -207,13 +205,13 @@ func (f *FileSystemStore) GetLeague() []Player {
}
```

The test should pass.
The test should pass.

## Refactor

We _have_ done this before! Our test code for the server had to decode the JSON from the response.
We _have_ done this before! Our test code for the server had to decode the JSON from the response.

Let's try DRYing this up into a function.
Let's try DRYing this up into a function.

Create a new file called `league.go` and put this inside.

Expand All @@ -238,7 +236,7 @@ We haven't got a strategy yet for dealing with parsing errors but let's press on

### Seeking problems

There is a flaw in our implementation. First of all let's remind ourselves how `io.Reader` is defined
There is a flaw in our implementation. First of all let's remind ourselves how `io.Reader` is defined.

```go
type Reader interface {
Expand All @@ -248,19 +246,19 @@ type Reader interface {

With our file you can imagine it reading through byte by byte until the end. What happens if you try and `Read` a second time?

Add the following to the end of our current test
Add the following to the end of our current test.

```go
// read again
got = store.GetLeague()
assertLeague(t, got, want)
```

We want this to pass, but if you run the test it doesnt.
We want this to pass, but if you run the test it doesn't.

The problem is our `Reader` has reached to the end so there is nothing more to read. We need a way to tell it to go back to the start.

[ReadSeeker](https://golang.org/pkg/io/#ReadSeeker) is another interface in the standard library that can help.
[ReadSeeker](https://golang.org/pkg/io/#ReadSeeker) is another interface in the standard library that can help.

```go
type ReadSeeker interface {
Expand Down Expand Up @@ -300,4 +298,4 @@ Next we'll implement `GetPlayerScore`
What we've covered:

- The `Seeker` interface and its relation with `Reader` and `Writer`
- Working with files
- Working with files

0 comments on commit 13f90ff

Please sign in to comment.