The Daily Go
337 subscribers
53 photos
2 videos
3 files
657 links
We provide you daily Golang contents. If you want to post any content contact with us.
.
Administrators:
👉🏻@aidenzibaei
👉🏻@amin_khozaei

#jaryan904259
Download Telegram
The Daily Go

Many suggest to use sync.Pool which is a fast, good implementation for temporary objects. But note that sync.Pool does not guarantee that pooled objects are retained. Quoting from its doc:

Any item stored in the Pool may be removed automatically at any time without notification. If the Pool holds the only reference when this happens, the item might be deallocated.

#Note #Pool
The Daily Go

Range and Close on Channels

A sender can close a channel to indicate that no more values will be sent. Receivers can test whether a channel has been closed by assigning a second parameter to the receive expression: after

v, ok := <-ch

ok is false if there are no more values to receive and the channel is closed.

The loop for i := range c receives values from the channel repeatedly until it is closed.

Note: Only the sender should close a channel, never the receiver. Sending on a closed channel will cause a panic.

Another note: Channels aren't like files; you don't usually need to close them. Closing is only necessary when the receiver must be told there are no more values coming, such as to terminate a range loop.

#Note #Channel
Today , Go 1.8 Released
The Daily Go
A FileSystem Abstraction System for Go

https://github.com/spf13/afero

#FS #Repository
Channel photo updated
The Daily Go
According to Golang blog about go1.8 :

The compiler and linker have been made faster. Compile times should be improved by about 15% over Go 1.7.

It's now much simpler to sort slices using the newly added Slice function in the sortpackage. For example, to sort a slice of structs by their Name field:

sort.Slice(s, func(i, j int) bool {
return s[i].Name < s[j].Name
})
This media is not supported in your browser
VIEW IN TELEGRAM
The Daily Go
Extract data from input using regular expressions.

like sed in bash

https://github.com/icholy/rip

#Repository