# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory # . or absolute path, please note that the directories following must be under root. root = "." tmp_dir = "tmp"
[build] # Just plain old shell command. You could use `make` as well. cmd = "go build -o ./tmp/main ." # Binary file yields from `cmd`. bin = "tmp/main" # Customize binary, can setup environment variables when run your app. full_bin = "APP_ENV=dev APP_USER=air ./tmp/main" # Watch these filename extensions. include_ext = ["go", "tpl", "tmpl", "html"] # Ignore these filename extensions or directories. exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"] # Watch these directories if you specified. include_dir = [] # Watch these files. include_file = [] # Exclude files. exclude_file = [] # Exclude specific regular expressions. exclude_regex = ["_test\\.go"] # Exclude unchanged files. exclude_unchanged = true # Follow symlink for directories follow_symlink = true # This log file places in your tmp_dir. log = "air.log" # It's not necessary to trigger build each time file changes if it's too frequent. delay = 0# ms # Stop running old binary when build errors occur. stop_on_error = true # Send Interrupt signal before killing process (windows does not support this feature) send_interrupt = false # Delay after sending Interrupt signal kill_delay = 500# ms # Add additional arguments when running binary (bin/full_bin). Will run './tmp/main hello world'. args_bin = ["hello", "world"]
[log] # Show log time time = false
[color] # Customize each part's color. If no color found, use the raw app log. main = "magenta" watcher = "cyan" build = "yellow" runner = "green"
[misc] # Delete tmp directory on exit clean_on_exit = true
// Sleep源码 // Sleep pauses the current goroutine for at least the duration d. // A negative or zero duration causes Sleep to return immediately. funcSleep(d Duration)
// Duration源码 // A Duration represents the elapsed time between two instants // as an int64 nanosecond count. The representation limits the // largest representable duration to approximately 290 years. type Duration int64
// ParseInt interprets a string s in the given base (0, 2 to 36) and // bit size (0 to 64) and returns the corresponding value i. // ParseInt在给定的base(0,2到36)和 bit 大小(0到64)中解释一个字符串s,并返回相应的值i。 // 位数(0-64),并返回相应的值i。 // The string may begin with a leading sign: "+" or "-". // 字符串可以以一个前导符号开始。"+"或"-"。 // If the base argument is 0, the true base is implied by the string's // prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", // 16 for "0x", and 10 otherwise. Also, for argument base 0 only, // underscore characters are permitted as defined by the Go syntax for // integer literals. // 如果基数参数为0,则真正的基数是由字符串的 // 符号后面的前缀(如果存在):2代表 "0b",8代表 "0 "或 "0o"。 // 16代表 "0x",否则就是10。另外,仅对参数base 0而言。 // 允许使用下划线字符,这是由Go的语法定义的 // 整数字元。 // The bitSize argument specifies the integer type // that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 // correspond to int, int8, int16, int32, and int64. // If bitSize is below 0 or above 64, an error is returned. // 比特尺寸参数指定了结果必须符合的整数类型。 // 结果必须符合的整数类型。比特大小为0、8、16、32和64 // 对应于int、int8、int16、int32和int64。 // 如果bitSize低于0或高于64,将返回一个错误。 // The errors that ParseInt returns have concrete type *NumError // and include err.Num = s. If s is empty or contains invalid // digits, err.Err = ErrSyntax and the returned value is 0; // if the value corresponding to s cannot be represented by a // signed integer of the given size, err.Err = ErrRange and the // returned value is the maximum magnitude integer of the // appropriate bitSize and sign. // ParseInt返回的错误有具体类型*NumError // 如果s是空的或者包含无效的数字,err.Er就会返回错误。 // err.Err = ErrSyntax,返回值为0。 // 如果对应于s的值不能由给定的有符号整数表示 // 如果s对应的值不能由给定大小的有符号整数表示,err.Err = ErrRange,返回值为0。 // err.Err = ErrRange,并且返回值是最大量级的整数。 // 适当的bitSize和符号。 funcParseInt(s string, base int, bitSize int) (i int64, err error) { const fnParseInt = "ParseInt"
if s == "" { return0, syntaxError(fnParseInt, s) }
// Pick off leading sign. s0 := s neg := false if s[0] == '+' { s = s[1:] } elseif s[0] == '-' { neg = true s = s[1:] }
// Convert unsigned and check range. var un uint64 un, err = ParseUint(s, base, bitSize) if err != nil && err.(*NumError).Err != ErrRange { err.(*NumError).Func = fnParseInt err.(*NumError).Num = s0 return0, err }
if bitSize == 0 { bitSize = IntSize }
cutoff := uint64(1 << uint(bitSize-1)) if !neg && un >= cutoff { returnint64(cutoff - 1), rangeError(fnParseInt, s0) } if neg && un > cutoff { return -int64(cutoff), rangeError(fnParseInt, s0) } n := int64(un) if neg { n = -n } return n, nil }
// strconv funcmain() { // 从字符串中解析对应的数字数据,字符串不能有非数字的字符 s := 100 ret := strconv.Itoa(s) fmt.Printf("ret=%v ret_type=%T\n", ret, ret) }
七、errors包
八、log包
九、io包
十、encoding包
X、rand包
rand模块可以用来生成随机数,是math包里的rand方法
注意:
生成随机数时,需要有一个种子,否则每次生成的随机数都是一样的
1 2 3 4 5 6 7
// rand源码 // Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n) // from the default Source. // It panics if n <= 0. funcIntn(n int)int { return globalRand.Intn(n) }