weathergo

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 9 Imported by: 0

README

weathergo

A module that retrieves weather information for a specified location using coordinates.

The l option retrieves the coordinates of a specified location.
If neither the l option nor the pref option is specified, the application calculates coordinates from the IP address and retrieves weather information for those coordinates.

Usage

$ go run ./cmd/weathergo/main.go -l 札幌 -days 3
Location: 北海道札幌市
Current Weather: Clouds generally forming or developing
Current Temp: 13.2°C, RH: 44%
Current Precip: 0.0mm, Pressure: 1012.2hPa

--- 3-Day Forecast ---
2026-04-29: Rain, not freezing, continuous, slight Max 13.2°C, Min 3.6°C, Precip Prob 94%
2026-04-30: Drizzle, not freezing, continuous, slight Max 18.1°C, Min 3.3°C, Precip Prob 66%
2026-05-01: Rain, not freezing, continuous, slight Max 15.1°C, Min 6.6°C, Precip Prob 100%
$ go run ./cmd/weathergo/main.go -pref=1 -days=5 -ja
場所: 北海道 札幌市
現在の天気: 空の状態に変化がない
気温: 4.5°C, 湿度: 81%
降水量: 0.0mm, 気圧: 1013.6hPa

--- 5日間の天気 ---
2026-04-28: 連続的な霧雨(弱い) 最高気温 9.0°C, 最低気温 4.3°C, 降水確率 95%
2026-04-29: 雲が形成されつつある、または発達しつつある 最高気温 12.9°C, 最低気温 2.9°C, 降水確率 96%
2026-04-30: 連続的な霧雨(弱い) 最高気温 17.8°C, 最低気温 2.9°C, 降水確率 29%
2026-05-01: 連続的な雨(弱い) 最高気温 16.9°C, 最低気温 5.9°C, 降水確率 60%
2026-05-02: 連続的な雨(弱い) 最高気温 13.1°C, 最低気温 7.1°C, 降水確率 78%
pref Option Code
コード 都道府県 都道府県庁所在地
1 北海道 札幌市
2 青森県 青森市
3 岩手県 盛岡市
4 宮城県 仙台市
5 秋田県 秋田市
6 山形県 山形市
7 福島県 福島市
8 茨城県 水戸市
9 栃木県 宇都宮市
10 群馬県 前橋市
11 埼玉県 さいたま市
12 千葉県 千葉市
13 東京都 新宿区
14 神奈川県 横浜市
15 新潟県 新潟市
16 富山県 富山市
17 石川県 金沢市
18 福井県 福井市
19 山梨県 甲府市
20 長野県 長野市
21 岐阜県 岐阜市
22 静岡県 静岡市
23 愛知県 名古屋市
24 三重県 津市
25 滋賀県 大津市
26 京都府 京都市
27 大阪府 大阪市
28 兵庫県 神戸市
29 奈良県 奈良市
30 和歌山県 和歌山市
31 鳥取県 鳥取市
32 島根県 松江市
33 岡山県 岡山市
34 広島県 広島市
35 山口県 山口市
36 徳島県 徳島市
37 香川県 高松市
38 愛媛県 松山市
39 高知県 高知市
40 福岡県 福岡市
41 佐賀県 佐賀市
42 長崎県 長崎市
43 熊本県 熊本市
44 大分県 大分市
45 宮崎県 宮崎市
46 鹿児島県 鹿児島市
47 沖縄県 那覇市

Data Sources & APIs

This project retrieves weather and location data using the following services:

  • GeoJS - IP-based Geolocation API for automatic location detection.
  • Geocoding.jp API - For converting Japanese address queries into geographic coordinates.
  • Open-Meteo - Weather forecast data.
    • Note: Weather data is provided by Open-Meteo.com under CC BY 4.0.

Documentation

Index

Constants

View Source
const DefaultPref = 13

Variables

This section is empty.

Functions

func GetWeatherName

func GetWeatherName(code int) string

Convert WMO codes to their corresponding strings.

func GetWeatherNameJa

func GetWeatherNameJa(code int) string

WMOコードを対応する日本語の文字列に変換する

Types

type Coodinate

type Coodinate struct {
	Latitude  float64
	Longitude float64
	Place     string
}

座標の定義

func GetAddressCoodinate added in v0.2.0

func GetAddressCoodinate(location string) (*Coodinate, error)

住所などの地名から座標の取得

func GetCoodinate

func GetCoodinate(loc string, pref int) (*Coodinate, error)

座標の取得

func GetIpAddrCoodinate

func GetIpAddrCoodinate() (*Coodinate, error)

IPアドレスから座標の取得

type DailyData

type DailyData struct {
	Time               []string  `json:"time"`
	WeatherCode        []int     `json:"weather_code"`
	Temperature2mMax   []float64 `json:"temperature_2m_max"`
	Temperature2mMin   []float64 `json:"temperature_2m_min"`
	PrecipitationSum   []float64 `json:"precipitation_sum"`
	PrecipitationHours []float64 `json:"precipitation_hours"`
}

type DailyUnits

type DailyUnits struct {
	Time               string `json:"time"`
	WeatherCode        string `json:"weather_code"`
	Temperature2mMax   string `json:"temperature_2m_max"`
	Temperature2mMin   string `json:"temperature_2m_min"`
	PrecipitationSum   string `json:"precipitation_sum"`
	PrecipitationHours string `json:"precipitation_hours"`
}

type HourlyData added in v0.4.0

type HourlyData struct {
	Time               []string  `json:"time"`
	Temperature2m      []float64 `json:"temperature_2m"`
	Precipitation      []float64 `json:"precipitation"`
	WindSpeed10m       []float64 `json:"wind_speed_10m"`
	WeatherCode        []int     `json:"weather_code"`
	RelativeHumidity2m []int     `json:"relative_humidity_2m"`
}

type HourlyForecast24h added in v0.4.0

type HourlyForecast24h struct {
	Times              []string
	Temperatures       []float64
	Precipitations     []float64
	WindSpeeds         []float64
	WeatherCodes       []int
	RelativeHumidities []int
}

先24時間分のデータを格納するための構造体

func GetNext24Hours added in v0.4.0

func GetNext24Hours(hourly HourlyData, timezone string) (*HourlyForecast24h, error)

HourlyDataから現在時刻以降の24時間分を抽出する関数

type HourlyUnits added in v0.4.0

type HourlyUnits struct {
	Time               string `json:"time"`
	Temperature2m      string `json:"temperature_2m"`
	Precipitation      string `json:"precipitation"`
	WindSpeed10m       string `json:"wind_speed_10m"`
	WeatherCode        string `json:"weather_code"`
	RelativeHumidity2m string `json:"relative_humidity_2m"`
}

type Location

type Location struct {
	Prefecture string  // 都道府県名
	City       string  // 都市名
	Latitude   float64 // 緯度
	Longitude  float64 // 経度
}

県庁所在地の情報を表す構造体

func GetPrefCapitalData

func GetPrefCapitalData(code int) (*Location, bool)

都道府県コードから Location を取得

type PrefectureCode

type PrefectureCode int

都道府県を表す値

type WMOWeatherCode

type WMOWeatherCode int

気象通報式コード(00-99)を表す型

type WeatherResponse

type WeatherResponse struct {
	Latitude             float64     `json:"latitude"`
	Longitude            float64     `json:"longitude"`
	GenerationtimeMs     float64     `json:"generationtime_ms"`
	UtcOffsetSeconds     int         `json:"utc_offset_seconds"`
	Timezone             string      `json:"timezone"`
	TimezoneAbbreviation string      `json:"timezone_abbreviation"`
	Elevation            float64     `json:"elevation"`
	HourlyUnits          HourlyUnits `json:"hourly_units"`
	Hourly               HourlyData  `json:"hourly"`
	DailyUnits           DailyUnits  `json:"daily_units"`
	Daily                DailyData   `json:"daily"`
}

func GetWeatherInfo

func GetWeatherInfo(latitude, longitude float64, useJma bool) (*WeatherResponse, error)

Directories

Path Synopsis
cmd
weathergo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL