Skip to content

YanhaoYang/gotchas-and-common-mistakes-in-go-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Opening Brace Can't Be Placed on a Separate Line

Unused Variables

Unused Imports

Short Variable Declarations Can Be Used Only Inside Functions

Redeclaring Variables Using Short Variable Declarations

Can't Use Short Variable Declarations to Set Field Values

Accidental Variable Shadowing

Can't Use "nil" to Initialize a Variable Without an Explicit Type

Using "nil" Slices and Maps

Map Capacity

Strings Can't Be "nil"

Array Function Arguments

Unexpected Values in Slice and Array "range" Clauses

Slices and Arrays Are One-Dimensional

Accessing Non-Existing Map Keys

Strings Are Immutable

Conversions Between Strings and Byte Slices

Strings and Index Operator

Strings Are Not Always UTF8 Text

String Length

Missing Comma In Multi-Line Slice, Array, and Map Literals

log.Fatal and log.Panic Do More Than Log

Built-in Data Structure Operations Are Not Synchronized

Iteration Values For Strings in "range" Clauses

Iterating Through a Map Using a "for range" Clause

Fallthrough Behavior in "switch" Statements

Increments and Decrements

Bitwise NOT Operator

Operator Precedence Differences

Unexported Structure Fields Are Not Encoded

App Exits With Active Goroutines

Sending to an Unbuffered Channel Returns As Soon As the Target Receiver Is Ready

Sending to an Closed Channel Causes a Panic

Using "nil" Channels

Methods with Value Receivers Can't Change the Original Value

Closing HTTP Response Body

Closing HTTP Connections

JSON Encoder Adds a Newline Character

JSON Package Escapes Special HTML Characters in Keys and String Values

Unmarshalling JSON Numbers into Interface Values

JSON String Values Will Not Be Ok with Hex or Other non-UTF8 Escape Sequences

Comparing Structs, Arrays, Slices, and Maps

Recovering From a Panic

Updating and Referencing Item Values in Slice, Array, and Map "range" Clauses

"Hidden" Data in Slices

Slice Data "Corruption"

"Stale" Slices

Type Declarations and Methods

Breaking Out of "for switch" and "for select" Code Blocks

Iteration Variables and Closures in "for" Statements

Deferred Function Call Argument Evaluation

Deferred Function Call Execution

Failed Type Assertions

Blocked Goroutines and Resource Leaks

Same Address for Different Zero-sized Variables

The First Use of iota Doesn't Always Start with Zero

Using Pointer Receiver Methods On Value Instances

Updating Map Value Fields

"nil" Interfaces and "nil" Interfaces Values

Stack and Heap Variables

GOMAXPROCS, Concurrency, and Parallelism

Read and Write Operation Reordering

Preemptive Scheduling

Import C and Multiline Import Blocks

No blank lines Between Import C and Cgo Comments

Can't Call C Functions with Variable Arguments

About

Source code of the article, 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages