Giter VIP home page Giter VIP logo

practical-go's Introduction

Practical Go for Developers

This repo contains the material for the "Practical Go Foundations" class. The code & links are synced with the [online class](for Developers).

This is an assorted collection of exercises for teaching, not a real Go project.

Setting Up

We highly recommend that you set up a local working environment and follow along with the videos. To setup a local environment install the following:

However, if you want to jump right in, you can use GitHub codespaces with the course repository. To start a codespaces follow these steps:

  • Click on the green "<> Code" button
  • Select the "Codespaces" tab
  • Click on the green "Create codespace on main" button

After a while you should have a new tab with Visual Studio Code already set up. You can read more about codespaces here.


Day 1

Agenda

  • Strings & formatted output
    • What is a string?
    • Unicode basics
    • Using fmt package for formatted output
  • Calling REST APIs
    • Making HTTP calls with net/http
    • Defining structs
    • Serializing JSON
  • Working with files
    • Handling errors
    • Using defer to manage resources
    • Working with io.Reader & io.Writer interfaces

Code

  • hw.go - Hello World
    • GOOS=drawin go build (also GOARCH)
  • banner.go - Strings & printing
  • github.go - Calling REST APIs
  • sha1.go - Working with io.Reader & io.Writer

Terminal Log

Links

Data & Other


Day 2

Agenda

  • Sorting
    • Working with slices
    • Writing methods
    • Understanding interfaces
  • Catching panics
    • The built-in recover function
    • Named return values
  • Processing text
    • Reading line by line with bufio.Scanner
    • Using regular expressions
    • Working with maps

Code

  • slices.go - Working with slices
  • game.go - Structs, methods & interfaces
  • empty.go - The empty interface, type assertions
  • div.go - Catching panics
  • freq.go - Most common word (files, regular expressions, maps)

Terminal Log

Exercises

  • Read and understand the sort package examples
  • Implement sortByDistance(players []Player, x, y int) in game.go
  • Change mostCommon to return the most common n words (e.g. func mostCommon(r io.Reader, n int) ([]string, error))

Links

Data & Other


Day 3

Agenda

  • Distributing work
    • Using goroutines & channels
    • Using the sync package to coordinate work
  • Timeouts & cancellation
    • Working with multiple channels using select
    • Using context for timeouts & cancellations
    • Standard library support for context

Code

Terminal Log

Exercise

In taxi_check.go

  • Limit the number of goroutines to "n". Which "n" yields the best results?
  • Cancel all goroutines once there's an error or mismatch in signature

Links

Data & Other


Day 4

Agenda

  • Testing your code
    • Working with the testing package
    • Using testify
    • Managing dependencies with go mod
  • Structuring your code
    • Writing sub-packages
  • Writing an HTTP server
    • Writing handlers
    • Using gorilla/mux for routing Adding metrics & logging
    • Using expvar for metrics
    • Using the log package and a look at user/zap
  • Configuration patterns
    • Reading environment variables and a look at external packages
    • Using the flag package for command line processing

Code

nlp project

├── go.mod - Project & dependencies
├── nlp.go - Package code
├── doc.go - Package level documentation
├── nlp_test.go - Test & benchmark file
├── example_test.go - Testable example
├── stemmer - Sub module
│   ├── stemmer.go
│   └── stemmer_test.go
├── testdata - Test data
│      └── tokenize_cases.toml - Test cases
└── cmd  - Executables
    └── nlpd - HTTP server
        ├── main.go
        └── main_test.go

Terminal Log

Links

Data & Other

practical-go's People

Contributors

tebeka avatar ardan-bkennedy avatar torelli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.