Skip to content

Add feature: integrate weatherxu API#204

Open
tinhuynh1 wants to merge 1 commit intoschachmat:masterfrom
tinhuynh1:feature/integrate-weatherxu-api
Open

Add feature: integrate weatherxu API#204
tinhuynh1 wants to merge 1 commit intoschachmat:masterfrom
tinhuynh1:feature/integrate-weatherxu-api

Conversation

@tinhuynh1
Copy link
Copy Markdown

Motivation and Context

Description

Steps for Testing

Screenshots

@tinhuynh1 tinhuynh1 force-pushed the feature/integrate-weatherxu-api branch from 6baddd8 to d25a66e Compare February 25, 2025 11:46
@tinhuynh1 tinhuynh1 force-pushed the feature/integrate-weatherxu-api branch from d25a66e to 1b9a20b Compare February 25, 2025 14:03
@kordianbruck kordianbruck requested a review from Copilot April 11, 2026 20:53
@kordianbruck
Copy link
Copy Markdown
Collaborator

Please rebase onto latest master.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new WeatherXu backend to fetch and render forecasts in wego, and documents how to configure it via .wegorc.

Changes:

  • Added a weatherxu backend implementation (API client + response parsing + backend registration).
  • Updated README setup instructions to include WeatherXu account/config guidance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
README.md Documents how to configure wego to use the new weatherxu backend.
backends/weatherxu.go Implements the WeatherXu API integration and registers the backend under iface.AllBackends["weatherxu"].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

debug bool
}

// WeatherXuResponse represents the main response structure
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "WeatherXuResponse" but the actual type is weatherXuResponse (unexported). This is confusing and will trigger golint-style checks; either rename the type to WeatherXuResponse or update/remove the comment so it matches the identifier.

Suggested change
// WeatherXuResponse represents the main response structure
// weatherXuResponse represents the main response structure

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +168
func (c *weatherXuConfig) Setup() {
flag.StringVar(&c.apiKey, "weatherxu-api-key", "", "weatherxu backend: the api `KEY` to use")
flag.StringVar(&c.lang, "weatherxu-lang", "en", "weatherxu backend: the `LANGUAGE` to request from weatherxu")
flag.BoolVar(&c.debug, "weatherxu-debug", false, "weatherxu backend: print raw requests and responses")
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-weatherxu-lang is defined and stored on the config, but c.lang is never used when building the WeatherXu request. Either remove the flag/config field, or pass the language through to the API (query parameter/header) so the option actually changes the response.

Copilot uses AI. Check for mistakes.
Comment on lines +331 to +335
s := strings.Split(location, ",")
loc = fmt.Sprintf("lat=%s&lon=%s", s[0], s[1])
requestUrl := fmt.Sprintf(weatherXuURI, loc)
resp, err := c.fetch(requestUrl)
if err != nil {
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numdays is never applied: the request URL does not include any forecast-days/limit parameter, and the parsed forecast is returned as-is. This breaks the global -days/config behavior; either request only numdays from WeatherXu (if supported) or trim ret.Forecast to numdays before returning.

Copilot uses AI. Check for mistakes.
Comment on lines +327 to +329
if matched, err := regexp.MatchString(`^-?[0-9]*(\.[0-9]+)?,-?[0-9]*(\.[0-9]+)?$`, location); !matched || err != nil {
log.Fatalf("Error: The weatherxu backend only supports latitude,longitude pairs as location %s.\n", location)
}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latitude/longitude validation regex allows empty values (e.g. "," matches because [0-9]* can be empty). Consider requiring at least one digit for both lat and lon (use + instead of *) so invalid locations fail fast with a clear error.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants