Skip to content

Instantly share code, notes, and snippets.

@Xe

Xe/1.md Secret

Created October 25, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xe/6cd20d412770fb03f4a958a8e664710d to your computer and use it in GitHub Desktop.
Save Xe/6cd20d412770fb03f4a958a8e664710d to your computer and use it in GitHub Desktop.

Go Training 1: Getting Go

  • Introduction to go
  • Installing go
    • hello world
    • go run
      • go run main.go
      • runs the code without creating a binary
      • good for testing programs iteratively
    • go build
      • creates a binary
      • good for distributing programs
  • using go modules
    • go mod init your.domain/path
    • this is all we will do for now with go modules
  • creating another go file: math.go
    • adding numbers
    • divide by zero
      • throw an error if the right hand side is zero
    • using functions in it in main.go

Go Training 2: Doing HTTP

  • Overview of how HTTP works
    • Clients make requests to servers
    • Servers return responses to clients
  • Making a HTTP request to icanhazip.com
    • import net/http
    • making the request object
      • http.NewRequest
    • getting the response
      • http.DefaultClient.Do
    • validating the response
      • status code 200
    • parsing the data
      • net.IP
      • throwing an error when it's wrong
    • error handling

Go Training 3

  • Testing
    • Test math.go
  • HTTP Testing
    • Testing the real production server
    • Creating a fake server
    • sending a HTTP request to that server via the make request function we made earlier
    • intentionally creating bad state
  • Adding contexts
    • Add the arguments
    • Add it to the HTTP request
    • Create test case for fake server timing out a context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment