Skip to content

Commit 9f0784e

Browse files
that-ar-guykashifkhan0771coderabbitai[bot]
authored
Update README.md (#9)
* Update README.md * name corrected * Created EXAMPLES.md * Updated EXAMPLES.md * Updated README.md * Updated README to reflect support for WeatherAPI only * Update EXAMPLES.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * 2/3 of the requested changed made * 3/3 of the requested changes made * some further changes --------- Co-authored-by: Kashif Khan <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 463d5df commit 9f0784e

File tree

2 files changed

+174
-24
lines changed

2 files changed

+174
-24
lines changed

EXAMPLES.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Examples for Go-API Client
2+
3+
## Example 1: Fetching Current Weather
4+
```go
5+
package main
6+
7+
import (
8+
"fmt"
9+
"github.com/kashifkhan0771/go-weather"
10+
)
11+
12+
func main() {
13+
client := weather.NewClient("YOUR_API_KEY")
14+
currentWeather, err := client.GetCurrentWeather("New York")
15+
if err != nil {
16+
fmt.Println("Error fetching weather:", err)
17+
return
18+
}
19+
20+
fmt.Printf("Current temperature in New York: %f°C\n", currentWeather.Temperature)
21+
}
22+
23+
```
24+
25+
## Example 2: Fetching a 5-Day Forecast
26+
```go
27+
Copy code
28+
package main
29+
30+
import (
31+
"fmt"
32+
"github.com/kashifkhan0771/go-weather"
33+
)
34+
35+
func main() {
36+
client := weather.NewClient("YOUR_API_KEY")
37+
forecast, err := client.GetForecast("Tokyo", 5)
38+
if err != nil {
39+
fmt.Println("Error fetching forecast:", err)
40+
return
41+
}
42+
43+
if forecast.Days == nil {
44+
fmt.Println("No forecast data available")
45+
return
46+
}
47+
for _, day := range forecast.Days {
48+
fmt.Printf("Date: %s, Temp: %f°C\n", day.Date, day.Temperature)
49+
}
50+
}
51+
```
52+
53+
## Example 3: Handling Errors
54+
```go
55+
Copy code
56+
package main
57+
58+
import (
59+
"fmt"
60+
"github.com/kashifkhan0771/go-weather"
61+
)
62+
63+
func main() {
64+
client := weather.NewClient("INVALID_API_KEY")
65+
_, err := client.GetCurrentWeather("Paris")
66+
if err != nil {
67+
fmt.Println("Error:", err)
68+
}
69+
70+
}
71+
```

README.md

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,112 @@
1-
# Go API Client
1+
# Go API Weather
22

3-
### API Docs:
4-
[WeatherAPI Documentation](https://www.weatherapi.com/docs/)
3+
[![Go Version](https://img.shields.io/github/go-mod/go-version/kashifkhan0771/go-weather)](https://golang.org/)
4+
[![License](https://img.shields.io/github/license/kashifkhan0771/go-weather)](LICENSE)
55

6-
### Usage:
7-
### Download:
8-
```bash
9-
go get "github.com/kashifkhan0771/go-weather"
6+
Go-Weather is a simple and efficient Go library for fetching weather information from [WeatherAPI](https://www.weatherapi.com). This library allows developers to seamlessly integrate weather data into their applications.
7+
8+
## Features
9+
- Fetch current weather for any location.
10+
- Retrieve forecast data for up to 7 days.
11+
- Supports WeatherAPI integration for reliable weather data.
12+
- Lightweight
13+
14+
## Installation
15+
In order to use Go-Weather, you need to have Go installed on your system. The library requires Go version 1.22.0 or higher.
16+
17+
```shell
18+
go get github.com/kashifkhan0771/go-weather
1019
```
11-
<code>
1220

13-
package main
21+
## Usage
22+
Import the library in your Go application:
1423

15-
import (
16-
"fmt"
17-
weatherClient "github.com/kashifkhan0771/go-weather"
18-
)
1924

20-
func main() {
21-
config, err := weatherClient.NewWeatherAPIConfig(<Your_API_Key>)
22-
if err != nil {
23-
panic(err)
24-
}
25+
```go
26+
package main
2527

26-
weather, err := config.GetCurrentWeather(weatherClient.Options{Query: "Paris"})
27-
if err != nil {
28-
panic(err)
29-
}
28+
import (
29+
"fmt"
30+
"github.com/kashifkhan0771/go-weather"
31+
)
3032

31-
fmt.Println(weather)
33+
func main() {
34+
client := weather.NewClient("YOUR_API_KEY")
35+
currentWeather, err := client.GetCurrentWeather("London")
36+
if err != nil {
37+
fmt.Println("Error fetching weather:", err)
38+
return
3239
}
33-
</code>
40+
41+
fmt.Printf("Current temperature in London: %f°C\n", currentWeather.Temperature)
42+
}
43+
```
44+
45+
## Configuration
46+
Set up your client with the API key provided by the weather service:
47+
48+
```go
49+
client := weather.NewClient("YOUR_API_KEY")
50+
```
51+
52+
### Advanced Congiguration
53+
Configure the client with additional options (if available):
54+
55+
```go
56+
client := weather.NewClient(
57+
"YOUR_API_KEY",
58+
weather.WithTimeout(10*time.Second),
59+
)
60+
```
61+
62+
## Supported Functions
63+
64+
### GetCurrentWeather
65+
66+
```go
67+
func GetCurrentWeather(location string) (*Weather, error)
68+
```
69+
70+
Fetches current weather for a given location.
71+
72+
Parameters:
73+
- `location`: City name, postal code, or coordinates
74+
75+
Returns:
76+
- `*Weather`: Weather information including temperature, conditions, etc.
77+
- `error`: API errors, network issues, or invalid location
78+
79+
### GetForecast
80+
81+
```go
82+
func GetForecast(location string, days int) (*Forecast, error)
83+
```
84+
85+
Retrieves weather forecast for specified days.
86+
87+
Parameters:
88+
- `location`: City name, postal code, or coordinates
89+
- `days`: Number of days (1-7)
90+
91+
Returns:
92+
- `*Forecast`: Forecast information for requested days
93+
- `error`: API errors, network issues, or invalid parameters
94+
95+
## Examples
96+
Detailed usage examples for each function are provided in the [EXAMPLES.md](EXAMPLES.md) file.
97+
98+
99+
## Contributing
100+
Contributions are welcome! Please follow the steps below:
101+
102+
- Fork the repository.
103+
- Create a feature branch: git checkout -b feature-name.
104+
- Commit your changes: git commit -m 'Add new feature'.
105+
- Push to your branch: git push origin feature-name.
106+
- Open a pull request.
107+
108+
## License
109+
This project is licensed under the MIT License. See the [LICENSE](https://github.com/kashifkhan0771/go-weather/blob/main/LICENSE) file for details.
110+
111+
## Acknowledgments
112+
Thanks to WeatherAPI for data integration.

0 commit comments

Comments
 (0)