Skip to content

Commit 7c57e9d

Browse files
authored
Go doc examples (#23)
1 parent 703261a commit 7c57e9d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

osmshortlink.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func interleaveBits(x uint32, y uint32) uint64 {
6161
return c
6262
}
6363

64+
// Decode a short string into a location and zoom.
6465
func Decode(s string) (float64, float64, int, error) {
6566
if len(s) < 1 {
6667
return 0, 0, 0, fmt.Errorf("invalid osm short link string %q", s)

osmshortlink_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package osmshortlink
22

33
import (
4+
"fmt"
45
"math"
56
"testing"
67
)
@@ -199,3 +200,30 @@ func TestDecodeShortLinkString(t *testing.T) {
199200
})
200201
}
201202
}
203+
204+
func ExampleCreate() {
205+
shortLink, err := Create(46.05141, 14.50604, 17)
206+
if err != nil {
207+
panic(err)
208+
}
209+
fmt.Println(shortLink)
210+
// Output: https://osm.org/go/0Ik3VNr_A-?m
211+
}
212+
213+
func ExampleEncode() {
214+
shortLink, err := Encode(46.05141, 14.50604, 17)
215+
if err != nil {
216+
panic(err)
217+
}
218+
fmt.Println(shortLink)
219+
// Output: 0Ik3VNr_A-
220+
}
221+
222+
func ExampleDecode() {
223+
latitude, longitude, zoom, err := Decode("0Ik3VNr_A-")
224+
if err != nil {
225+
panic(err)
226+
}
227+
fmt.Println(latitude, longitude, zoom)
228+
// Output: 46.05140447616577 14.506051540374756 17
229+
}

0 commit comments

Comments
 (0)