Go uses a small note

1, can not use the value calculated at run-time instances of such arrays.
But the use of make initialization sections having a desired length.

db := ConnMysql()
rows, err := db.Query("select rules from u_check_list where status= ? and web_uri=? and server_ip=? order by rank ", 1, web, server)
helper.CheckErr(err)
columns, err := rows.Columns()
helper.CheckErr(err)
var rules = [len(columns)]string

Error Message: non-constant array bound len(columns)

这样写:
 columns, err := rows.Columns()
 helper.CheckErr(err)
 var ruleLength = len(columns)
 var rules = make([]string, ruleLength)

2, slice Slice, one can dynamically change the size of the array.
The most important feature: a variable length; different lengths, two slices will be different

3, channel, initialization time if you set the cache capacity, we should note that the maximum capacity is reached, if not yet reached the maximum reading, this time again to write the data channel will fail

4, variable names must be careful not conflict with keywords; do not conflict with the package name, the package can not or will import

5, the difference between concurrency and parallelism:
Concurrent: single core cpu, you can do a number of things, but at some point, to do only one task, when the task is blocked, cpu can immediately wake up on top of other tasks, so the task always in progress. For example, a hand playing phone, play games, watch videos into play irritable
parallel: multi-core cpu, you can do a number of things at the same time. Then each time point, if there is more than one task, then the task of simultaneously doing. For example, a man came home from work, listening to music while reading a book

Guess you like

Origin www.cnblogs.com/xinxinmifan/p/go-learning-notes.html