Golang input/output: Difference between revisions
From wikinotes
(→Printf) |
No edit summary |
||
Line 41: | Line 41: | ||
</blockquote><!-- printf --> | </blockquote><!-- printf --> | ||
</blockquote><!-- print --> | </blockquote><!-- print --> | ||
= Streams = | |||
<blockquote> | |||
</blockquote><!-- Streams --> | |||
= Networking = | |||
<blockquote> | |||
== Sockets == | |||
<blockquote> | |||
</blockquote><!-- Sockets --> | |||
== HTTP == | |||
<blockquote> | |||
</blockquote><!-- HTTP --> | |||
</blockquote><!-- Networking --> |
Revision as of 23:50, 5 June 2022
Basics
require "fmt" fmt.Println("foo") // print to stdout with newline fmt.Printf("%v", 123) // print formatted string to stdout (no newline) fmt.Fprintf(os.Stdout, "%v", 123) // prints formatted string to writable object (ex. STDOUT, STERR, ..) fmt.Sprintf("%v", 123) // returns formatted string (no newline)Format Syntax
Printf/Sprintf/Fprintf all take format specifiers.
See full docs here, but here's some really useful formats:# general %v # value %T # type # number-bases %b # binary %x # hex %o # octal %d # decimal # number types %i # int %f # float # strings %s # string %q # quoted/escaped go string %c # unicode-char for num
Streams
Networking
Sockets
HTTP