-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bugfix/mismatch-assign-panic
- Loading branch information
Showing
196 changed files
with
1,234 additions
and
3,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"sync" | ||
) | ||
|
||
func humanizeBytes(bytes uint64) string { | ||
const ( | ||
_ = iota | ||
kB uint64 = 1 << (10 * iota) | ||
mB | ||
gB | ||
tB | ||
pB | ||
) | ||
|
||
switch { | ||
case bytes < kB: | ||
return fmt.Sprintf("%dB", bytes) | ||
case bytes < mB: | ||
return fmt.Sprintf("%.2fKB", float64(bytes)/float64(kB)) | ||
case bytes < gB: | ||
return fmt.Sprintf("%.2fMB", float64(bytes)/float64(mB)) | ||
case bytes < tB: | ||
return fmt.Sprintf("%.2fGB", float64(bytes)/float64(gB)) | ||
case bytes < pB: | ||
return fmt.Sprintf("%.2fTB", float64(bytes)/float64(tB)) | ||
default: | ||
return fmt.Sprintf("%dB", bytes) | ||
} | ||
} | ||
|
||
func main() { | ||
i := 0 | ||
wg := sync.WaitGroup{} | ||
|
||
for { | ||
var m runtime.MemStats | ||
runtime.ReadMemStats(&m) | ||
fmt.Printf("#%d: alloc = %s, routines = %d, gc = %d\n", i, humanizeBytes(m.Alloc), runtime.NumGoroutine(), m.NumGC) | ||
|
||
wg.Add(1) | ||
go func() { | ||
wg.Done() | ||
}() | ||
wg.Wait() | ||
i = i + 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
func ShortVariableDeclarations() (i int, err error) { | ||
r, err := 1, errors.New("test") | ||
i = r | ||
return | ||
} | ||
|
||
func main() { | ||
_, er := ShortVariableDeclarations() | ||
if er != nil { | ||
println("ShortVariableDeclarations ok") | ||
} else { | ||
println("ShortVariableDeclarations not ok") | ||
} | ||
} | ||
|
||
// Output: | ||
// ShortVariableDeclarations ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
func main() { | ||
myMap := map[string]int{"a":2} | ||
|
||
for s, _ := range myMap { | ||
_ = s | ||
} | ||
println("ok") | ||
} | ||
|
||
// Output: | ||
// ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.