Skip to content

Commit

Permalink
Go doc examples (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanb authored Jun 10, 2024
1 parent 703261a commit 7c57e9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions osmshortlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func interleaveBits(x uint32, y uint32) uint64 {
return c
}

// Decode a short string into a location and zoom.
func Decode(s string) (float64, float64, int, error) {
if len(s) < 1 {
return 0, 0, 0, fmt.Errorf("invalid osm short link string %q", s)
Expand Down
28 changes: 28 additions & 0 deletions osmshortlink_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package osmshortlink

import (
"fmt"
"math"
"testing"
)
Expand Down Expand Up @@ -199,3 +200,30 @@ func TestDecodeShortLinkString(t *testing.T) {
})
}
}

func ExampleCreate() {
shortLink, err := Create(46.05141, 14.50604, 17)
if err != nil {
panic(err)
}
fmt.Println(shortLink)
// Output: https://osm.org/go/0Ik3VNr_A-?m
}

func ExampleEncode() {
shortLink, err := Encode(46.05141, 14.50604, 17)
if err != nil {
panic(err)
}
fmt.Println(shortLink)
// Output: 0Ik3VNr_A-
}

func ExampleDecode() {
latitude, longitude, zoom, err := Decode("0Ik3VNr_A-")
if err != nil {
panic(err)
}
fmt.Println(latitude, longitude, zoom)
// Output: 46.05140447616577 14.506051540374756 17
}

0 comments on commit 7c57e9d

Please sign in to comment.