1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 02:47:04 +00:00

new party controllers example

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-01-08 19:54:33 +02:00
parent 48577b7ff1
commit f633ab4b99
10 changed files with 537 additions and 5 deletions

View File

@@ -0,0 +1,43 @@
package weatherapi
import (
"context"
"net/url"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/x/client"
)
// The BaseURL of our API client.
const BaseURL = "https://api.weatherapi.com/v1"
type (
Options struct {
APIKey string `json:"api_key" yaml:"APIKey" toml:"APIKey"`
}
Client struct {
*client.Client
}
)
func NewClient(opts Options) *Client {
apiKeyParameterSetter := client.RequestParam("key", opts.APIKey)
c := client.New(client.BaseURL(BaseURL),
client.PersistentRequestOptions(apiKeyParameterSetter))
return &Client{c}
}
func (c *Client) GetCurrentByCity(ctx context.Context, city string) (resp Response, err error) {
urlpath := "/current.json"
// ?q=Athens&aqi=no
params := client.RequestQuery(url.Values{
"q": []string{city},
"aqi": []string{"no"},
})
err = c.Client.ReadJSON(ctx, &resp, iris.MethodGet, urlpath, nil, params)
return
}