Backend development

Stage 1 · Lesson 4 of 10

Interfaces

Your language and how HTTP works

A Go is a list of methods. Any type that has those methods fits the interface automatically, with no implements keyword. That makes small interfaces very powerful.

io.Reader has just one method, and files, network connections, bodies and buffers all fit it. Define an interface where it is used, not where the types are declared, and keep it to one or two methods. The usual advice is "accept interfaces, return structs". This is how you will later swap a real database for a fake one in tests.

Common trapa stored in an interface. The interface itself is not nil, so a check like err != nil is true, even though the value inside is a nil pointer.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

  • CourseFree
    A Tour of Go

    The Go Authors · Beginner

    The official interactive tour: basics, methods, interfaces, generics and concurrency

Practise

  • Your language track: small exercises with free mentor feedback on idiomatic code

Keep handy

  • Short runnable examples to look up while you write: errors, JSON, goroutines, testing

  • Read the HTTP overview, methods, headers and status code pages until they feel obvious

Also worth your time

Mark this stage as not done?