Go Recipes: Difference between revisions
Jump to navigation
Jump to search
(→Files) |
|||
(42 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= | =TO DEPLETE and MERGE= | ||
<font color=darkkhaki> | |||
Into [[Go Code Examples]] | |||
= | |||
=Files= | |||
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | <blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | ||
* Reading a file with <tt>[[Go Package os|os]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/read-file.go playground/go/files/read-file.go] | * Reading a file with <tt>[[Go Package os|os]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/read-file.go playground/go/files/read-file.go] | ||
* Readinga file with <tt>[[Go Package io|io/ioutil]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/read-file-2.go playground/go/files/read-file-2.go] | * Readinga file with <tt>[[Go Package io|io/ioutil]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/read-file-2.go playground/go/files/read-file-2.go] | ||
* Writing a file with <tt>[[Go Package os|os]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/write-file.go playground/go/files/write-file.go] | |||
* Writing a file with <tt>[[Go Package io|io/ioutil]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/write-file-2.go playground/go/files/write-file-2.go] | |||
* Reading a directory with <tt>[[Go Package os|os]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/read-dir.go playground/go/files/read-dir.go] | |||
* Walking a directory with <tt>[[File_Paths_and_Names_in_Go#filepath|filepath]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/files/walk-dir.go playground/go/files/walk-dir.go] | |||
</blockquote> | |||
=Network= | |||
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | |||
* TCP client and server with <tt>[[Go Package net|net]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/network/tcp-server.go playground/go/network/tcp-server.go], [https://github.com/NovaOrdis/playground/blob/master/go/network/tcp-client.go playground/go/network/tcp-client.go], | |||
* HTTP server with <tt>[[Go Package net|net/http]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/network/http-server.go playground/go/network/http-server.go] | |||
* HTTP client with <tt>[[Go Package net|net/http]]</tt> and <tt>[[Go Package io|ioutil]]</tt> primitives: [https://github.com/NovaOrdis/playground/blob/master/go/network/http-client.go playground/go/network/http-client.go] <font color=red>More HTTP details in "Go in Action" page 65.</font> | |||
* RPC - Introducing Go page 89 | |||
</blockquote> | |||
=Command Line Parsing= | |||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | |||
:[[Go Command Line Parsing]] | |||
</blockquote> | </blockquote> | ||
=Concurrency= | |||
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | |||
* Unbuffered channel: [https://github.com/NovaOrdis/playground/blob/master/go/concurrency/unbuffered-channel.go playground/go/concurrency/unbuffered-channel.go] | |||
* <span id="waitGroup_example">Using</span> a <tt>waitGroup</tt> to wait for goroutines to finish before exiting <tt>main()</tt>: [https://github.com/NovaOrdis/playground/blob/master/go/concurrency/waitGroup.go playground/go/concurrency/waitGroup.go] | |||
</blockquote> | |||
=Logging= | |||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | |||
:[[Go_Package_log#Changing_the_Logging_Device|Changing the Logging Device]] | |||
</blockquote> | |||
=Sleeping= | |||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | |||
:[[Go_Package_time#time.Sleep.28.29|sleep]] | |||
</blockquote> | |||
=Miscellaneous= | |||
* Using channels to monitor the amount of time a program is running and time it out, signals: "Go in Action" Section 7.1 Runner (page 179), [https://github.com/NovaOrdis/playground/blob/master/go/go-in-action/runner playground/go/go-in-action/runner] | |||
* Pooling "Go in Action" Section 7.2 page 188 | |||
* Workers "Go in Action" Section 7.3 page 198 | |||
=Conventions and Idioms= | |||
* Name factory functions <tt>New</tt>. The factory functions should return a value or a pointer depending on the [[Go_Concepts_-_The_Type_System#Primitive_vs._Non-Primitive_Nature|primitive nature of the type]]. |
Latest revision as of 22:23, 16 October 2023
TO DEPLETE and MERGE
Into Go Code Examples
Files
- Reading a file with os primitives: playground/go/files/read-file.go
- Readinga file with io/ioutil primitives: playground/go/files/read-file-2.go
- Writing a file with os primitives: playground/go/files/write-file.go
- Writing a file with io/ioutil primitives: playground/go/files/write-file-2.go
- Reading a directory with os primitives: playground/go/files/read-dir.go
- Walking a directory with filepath primitives: playground/go/files/walk-dir.go
Network
- TCP client and server with net primitives: playground/go/network/tcp-server.go, playground/go/network/tcp-client.go,
- HTTP server with net/http primitives: playground/go/network/http-server.go
- HTTP client with net/http and ioutil primitives: playground/go/network/http-client.go More HTTP details in "Go in Action" page 65.
- RPC - Introducing Go page 89
Command Line Parsing
Concurrency
- Unbuffered channel: playground/go/concurrency/unbuffered-channel.go
- Using a waitGroup to wait for goroutines to finish before exiting main(): playground/go/concurrency/waitGroup.go
Logging
Sleeping
Miscellaneous
- Using channels to monitor the amount of time a program is running and time it out, signals: "Go in Action" Section 7.1 Runner (page 179), playground/go/go-in-action/runner
- Pooling "Go in Action" Section 7.2 page 188
- Workers "Go in Action" Section 7.3 page 198
Conventions and Idioms
- Name factory functions New. The factory functions should return a value or a pointer depending on the primitive nature of the type.