Skip to content

Instantly share code, notes, and snippets.

Avatar

Krzysztof Kowalczyk kjk

View GitHub Profile
@kjk
kjk / main.go
Created Nov 5, 2019
Error handling
View main.go
// :collection Essential Go
package main
import (
"fmt"
"math"
)
// :show start
func sqrt(n float64) (float64, error) {
View main.go
// :collection Essential Go
package main
import (
"fmt"
"sync"
"time"
)
// :show start
@kjk
kjk / main.go
Created Nov 5, 2019
Channels and select
View main.go
// :collection Essential Go
package main
import (
"fmt"
"math/rand"
)
// :show start
@kjk
kjk / main.go
Last active Nov 5, 2019
Interfaces
View main.go
// :collection Essential Go
package main
import (
"fmt"
"strconv"
)
// :show start
// Stringer is an interface with a single method
View main.go
// :collection Essential Go
package main
import "fmt"
// :show start
type Person struct {
FirstName string
LastName string
}
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
a := [2]int{4, 5} // array of 2 ints
// access element of array
View main.go
// :collection Essential Go
package main
import (
"bytes"
"fmt"
"io"
)
// :show start
View main.go
// :collection Essential Go
package main
import (
"encoding/xml"
"fmt"
"log"
)
// :show start
@kjk
kjk / main.go
Created Nov 5, 2019
Serialize a struct as XML
View main.go
// :collection Essential Go
package main
import (
"encoding/xml"
"fmt"
"log"
)
// :show start
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
m := make(map[string]int)
// set the value