Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The reference is about Go lang in Modern Web conference 2019
  • Using Go modules

  • Go lang doc

  • Makefile

  • Go asserts module

  • A Go module datastore and proxy

  • Go API (Health check for load balencer)

  • Command line package

    • flag
    • urfave/cli
    • spf13/cobra
  • Config management

    • joho/godotenv
  • Go 每個在 GitHub 專案都不太一樣,專案的架構目錄應依照每個團隊會做調整

  • /Configs 目錄,把全部設定檔都放在此目錄

  • /docker 目錄,把全部有關的docker目錄都放在此

  • testcontainers/testcontainers-go 測試/驗證 編好的 container 是否正確

  • pkg/errors

  • Rails-like test fixtures (測試用到的檔案都放在 fixtures 目錄)

Unit tests in Go

  • TestMain (預設測試會先走此 function 之後再往下作其他的測試)
  • /pkg/helper (看需求放一些常用的 function)
  • /pkg/model (xorm, gorm) Database manipulation middleware (Object oriented mapping)
  • /pkg/schema (GraphQL in Go), RESTful API

Best practices Testing Go codes

  • Testable code
    • code quality
    • readability
    • maintainability

Benchmarking in Go

  • Write Go to do benchmarking

Example testing

ExampleFooBar() {......}

Subtests in testing package

Skipping testing

  • 在某個情況環境才可以跑,local環境不行

平行處理 (Async task processing)

Just only use one package

  • testify (Go Mocks)
  • stretchr/testify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.