Skip to content

Instantly share code, notes, and snippets.

View batic420's full-sized avatar

Basti batic420

  • Germany
View GitHub Profile
@satyrius
satyrius / exercise-56.go
Created October 23, 2013 06:33
A Tour of Go. Exercise: Errors. Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt should return a non-nil error value when given a negative number, as it doesn't support complex numbers. Create a new type type ErrNegativeSqrt float64 and make it an error by giving it a func (e ErrNegativeSqrt) Error(…
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %v", float64(e))
@danimal141
danimal141 / exercise-stringer.go
Last active June 15, 2026 20:47
A Tour of Go Exercise: Stringers
package main
import (
"fmt"
"strings"
"strconv"
)
type IPAddr [4]byte