Skip to content

Commit

Permalink
small cleanup items
Browse files Browse the repository at this point in the history
  • Loading branch information
icodealot committed Aug 28, 2022
1 parent 41858c7 commit 7046d91
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Data on various weather.gov API endpoints is measured at different intervals. If

## API

This API is currently a minimal subset of what api.weather.gov supports and includes the following:
`noaa` is a Go client for the weather.gov API and supports the following endpoints:

```go
noaa.Points(lat string, lon string) (points *PointsResponse, err error)
noaa.Points(lat string, lon string) (points *PointsResponse, err error) {
```
```go
noaa.Office(id string) (office *OfficeResponse, err error)
noaa.Office(id string) (office *OfficeResponse, err error) {
```
```go
Expand Down Expand Up @@ -63,6 +63,7 @@ package main

import (
"fmt"

"github.com/icodealot/noaa"
)

Expand Down
9 changes: 5 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ var config = GetDefaultConfig()
// future weather.gov might change this behavior.
// See http://www.weather.gov/documentation/services-web-api
type Config struct {
BaseURL string `json:"baseUrl"` // not including a trailing slash
BaseURL string `json:"baseUrl"` // Do not include a trailing slash
UserAgent string `json:"apiKey"` // ex. (myweatherapp.com, [email protected])
Accept string `json:"accept"` // application/geo+json, etc. defaults to ld+json
Units string `json:"units"` // "us" (the default if blank) or "si" for metric
Debug bool `json:"debug"` // set to true to
}

// SetUserAgent changes the string used for the User-Agent header when making
// requests. See https://www.weather.gov/documentation/services-web-api
// (Authentication) for details. By default, this library uses the github.com URL.
// (Authentication) for details. By default, this module uses a github.com URL.
func SetUserAgent(userAgent string) {
if len(userAgent) == 0 {
panic("the api requires a user-agent")
Expand Down Expand Up @@ -48,12 +47,14 @@ func SetConfig(c Config) {
config = c
}

// GetConfig is used to return the current configuration of the API. This allows
// GetConfig is used to return the current configuration of the client. This allows
// for testing and inspection as needed.
func GetConfig() Config {
return config
}

// GetDefaultConfig returns a config struct that can be used as a starting point
// for configuration changes. See examples in `example_test.go`.
func GetDefaultConfig() Config {
return Config{
BaseURL: API,
Expand Down
2 changes: 1 addition & 1 deletion noaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func apiCall(endpoint string) (res *http.Response, err error) {
return nil, err
}

if res.StatusCode != 200 {
if res.StatusCode != http.StatusOK {
return nil, errors.New(fmt.Sprintf("%d %s", res.StatusCode, res.Status))
}

Expand Down

0 comments on commit 7046d91

Please sign in to comment.