core

module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2023 License: MIT

README

Contributors Forks Stargazers Issues MIT License LinkedIn

OpenCamp

Simple Go library for interacting with the recreation.gov API.

Usage

Search for a campground
l := log15.New()
c := client.New(l, 10*time.Second)
campgrounds, err := c.Suggest("kirk creek")
if err != nil {
  // handle err
}
if len(campgrounds) == 0 {
  fmt.Println("Sorry, no campgrounds with that name were found.")
  return
}

bytes, err := json.MarshalIndent(campgrounds, "", "  ")
if err != nil {
  // handle err
}

fmt.Println(string(bytes))
Check campground availability
l := log15.New()
c := client.New(l, 10*time.Second)

sites, err := c.Availability("233116", "09-11-2023", "09-13-2023")
if err != nil {
  // handle err
}

if len(sites) == 0 {
  fmt.Println("Sorry we didn't find any available campsites!")
} else {
  fmt.Println("The following sites are available for those dates:")
  for _, s := range sites {
    fmt.Printf(" - Site %-15s Book at: https://www.recreation.gov/camping/campsites/%s\n", s.Site, s.CampsiteID)
  }
}
Poll campground availability
l := log15.New()
c := client.New(l, 10*time.Second)
ctx := context.Background()

// Blocking operation.
sites, err := c.Poll(ctx, "233116", "09-11-2023", "09-13-2023", "1m")
if err != nil {
  // handle err
}

fmt.Println("Just in! The following sites are now available for those dates:")
for _, s := range sites {
  fmt.Printf(" - Site %-15s Book at: https://www.recreation.gov/camping/campsites/%s\n", s.Site, s.CampsiteID)
}
Retrieve campground data by ID
l := log15.New()
c := client.New(l, 10*time.Second)
campground, err := c.SearchByID("233116")
if err != nil {
  // handle err
}

bytes, err := json.MarshalIndent(campground, "", "  ")
if err != nil {
  // handle err
}

fmt.Println(string(bytes))

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL