noaago is a Go client for fetching tidal data and finding station metadata from NOAA.
go get github.com/tpryan/noaagopackage main
import (
"fmt"
"log"
"time"
"github.com/tpryan/noaago"
)
func main() {
client := noaago.NewClient()
// 1. Find nearby stations (e.g., San Francisco)
stationOpts := noaago.NewStationOptionsBuilder().
Nearby(37.8086, -122.4764, 10). // 10 mile radius
Type(noaago.StationTypeWaterLevels).
Build()
stations, err := client.FindStations(stationOpts)
if err != nil {
log.Fatal(err)
}
if len(stations.Stations) == 0 {
log.Fatal("No stations found")
}
station := stations.Stations[0]
fmt.Printf("Found station: %s (%s)\n", station.Name, station.ID)
// 2. Get Tidal Data for that station (last 24 hours)
tideOpts := noaago.NewTideOptionsBuilder().
StationID(station.ID).
DateRange(time.Now().Add(-24*time.Hour), time.Now()).
Product(noaago.ProductWaterLevel).
Datum(noaago.DatumMLLW).
Units(noaago.UnitsMetric).
TimeZone(noaago.TimeZoneGMT).
Build()
data, err := client.GetTides(tideOpts)
if err != nil {
log.Fatal(err)
}
for _, dp := range data.Data {
val, _ := dp.ValueFloat()
fmt.Printf("Time: %s, Level: %.3f\n", dp.Time, val)
}
}Used for finding stations via client.FindStations().
| Method | Description |
|---|---|
Nearby(lat, lon, radius) |
Filters stations within radius miles of the given coordinates. |
Unit(RadiusUnit) |
Sets the unit for the search radius (defaults to Miles). |
Type(StationType) |
Filters by station type (e.g., noaago.StationTypeWaterLevels). |
Used for fetching data via client.GetTides().
| Method | Description |
|---|---|
StationID(string) |
Sets the NOAA station ID (required). |
DateRange(start, end) |
Sets the time range for data. |
Product(ProductType) |
Sets the data product (e.g., Water Level, Wind). |
Datum(Datum) |
Sets the vertical datum (e.g., MLLW, MSL). |
Units(Units) |
Sets the units (Metric or English). |
TimeZone(TimeZone) |
Sets the time zone (GMT, LST, LST_LDT). |
Interval(Interval) |
Sets the data interval (e.g., High/Low, Hourly). |
The Client struct has exported fields that can be modified after initialization:
client := noaago.NewClient()
client.UserAgent = "My-App/1.0" // Custom User-Agent header
client.HTTPClient = &http.Client{Timeout: 30 * time.Second} // Custom HTTP ClientProductWaterLevel: 6-minute water level dataProductPredictions: Tide predictionsProductAirTemp: Air temperatureProductWaterTemp: Water temperatureProductWind: Wind speed, direction, and gustsProductAirPressure: Barometric pressureProductConductivity: ConductivityProductVisibility: VisibilityProductHumidity: HumidityProductSalinity: SalinityProductHourlyHeight: Hourly water levelsProductHighLow: High and Low water levelsProductDailyMean: Daily mean water levelProductMonthlyMean: Monthly mean water levelProductOneMinuteWaterLevel: One minute water level
DatumMLLW: Mean Lower Low WaterDatumMHW: Mean High WaterDatumMSL: Mean Sea LevelDatumSTND: Station DatumDatumMHHW: Mean Higher High WaterDatumMLW: Mean Low WaterDatumNAVD: North American Vertical Datum
StationTypeWaterLevelsStationTypeCurrents
UnitsMetric: Celsius, Meters, etc.UnitsEnglish: Fahrenheit, Feet, etc.
TimeZoneGMT: Greenwich Mean TimeTimeZoneLST: Local Standard TimeTimeZoneLSTLDT: Local Standard/Daylight Time
IntervalHighLow: High/Low tidesIntervalHourly: Hourly data- (Default): 6-minute intervals
RadiusUnitMiles(Default)RadiusUnitKilometersRadiusUnitNauticalMiles
- Fluent Interface: Builder pattern for configuring requests.
- Dual API Support: Handles both Data (
datagetter) and Metadata (mdapi) APIs transparently. - Type Safety: Enums for Products, Datums, Units, etc.
Apache 2.0
This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.