From a3fa7ef5e65b62c9d8b6af9148f62d9e1d148073 Mon Sep 17 00:00:00 2001 From: Fajar Lubis Date: Thu, 21 Dec 2023 21:54:22 +0700 Subject: [PATCH 1/2] skeleton --- affected_earthquake.go | 3 ++- const.go | 5 +++++ http_wrapper.go | 1 + latest_earthquake.go | 4 ++-- recents_earthquake.go | 3 ++- 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 const.go create mode 100644 http_wrapper.go diff --git a/affected_earthquake.go b/affected_earthquake.go index 3bb519a..6975d09 100644 --- a/affected_earthquake.go +++ b/affected_earthquake.go @@ -3,6 +3,7 @@ package gempago import ( "encoding/json" "errors" + "fmt" "io" "net/http" "strconv" @@ -11,7 +12,7 @@ import ( ) func AffectedEarthQuake() ([]*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, "https://data.bmkg.go.id/DataMKG/TEWS/gempadirasakan.json", nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/gempadirasakan.json", BMKG_URL), nil) if err != nil { return nil, err } diff --git a/const.go b/const.go new file mode 100644 index 0000000..6300f17 --- /dev/null +++ b/const.go @@ -0,0 +1,5 @@ +package gempago + +const ( + BMKG_URL = "https://data.bmkg.go.id/DataMKG" +) diff --git a/http_wrapper.go b/http_wrapper.go new file mode 100644 index 0000000..728d23f --- /dev/null +++ b/http_wrapper.go @@ -0,0 +1 @@ +package gempago diff --git a/latest_earthquake.go b/latest_earthquake.go index 75e4c14..985887b 100644 --- a/latest_earthquake.go +++ b/latest_earthquake.go @@ -12,7 +12,7 @@ import ( ) func LatestEarthQuake() (*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, "https://data.bmkg.go.id/DataMKG/TEWS/autogempa.json", nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/autogempa.json", BMKG_URL), nil) if err != nil { return nil, err } @@ -79,7 +79,7 @@ func LatestEarthQuake() (*EarthQuakeData, error) { earthQuakeData.Potential = data.InfoGempa.Gempa.Potensi earthQuakeData.AffectedRegion = data.InfoGempa.Gempa.Dirasakan - earthQuakeData.Shakemap = fmt.Sprintf("https://data.bmkg.go.id/DataMKG/TEWS/%s", data.InfoGempa.Gempa.Shakemap) + earthQuakeData.Shakemap = fmt.Sprintf("%s/TEWS/%s", BMKG_URL, data.InfoGempa.Gempa.Shakemap) return &earthQuakeData, nil } diff --git a/recents_earthquake.go b/recents_earthquake.go index 12ab5e5..1d95af4 100644 --- a/recents_earthquake.go +++ b/recents_earthquake.go @@ -3,6 +3,7 @@ package gempago import ( "encoding/json" "errors" + "fmt" "io" "net/http" "strconv" @@ -11,7 +12,7 @@ import ( ) func RecentsEarthQuake() ([]*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, "https://data.bmkg.go.id/DataMKG/TEWS/gempaterkini.json", nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/gempaterkini.json", BMKG_URL), nil) if err != nil { return nil, err } From 34e99fc373205969c84c267093349c99a61620cb Mon Sep 17 00:00:00 2001 From: Fajar Lubis Date: Fri, 22 Dec 2023 07:19:23 +0700 Subject: [PATCH 2/2] change const name --- affected_earthquake.go | 4 +++- const.go | 3 ++- latest_earthquake.go | 4 ++-- recents_earthquake.go | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/affected_earthquake.go b/affected_earthquake.go index 6975d09..7bf197d 100644 --- a/affected_earthquake.go +++ b/affected_earthquake.go @@ -11,8 +11,10 @@ import ( "time" ) +// TODO add exponential backoff algorithm + func AffectedEarthQuake() ([]*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/gempadirasakan.json", BMKG_URL), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/gempadirasakan.json", _BMKG), nil) if err != nil { return nil, err } diff --git a/const.go b/const.go index 6300f17..e4a41f9 100644 --- a/const.go +++ b/const.go @@ -1,5 +1,6 @@ package gempago const ( - BMKG_URL = "https://data.bmkg.go.id/DataMKG" + _BMKG = "https://data.bmkg.go.id/DataMKG/TEWS" + _USGS = "" ) diff --git a/latest_earthquake.go b/latest_earthquake.go index 985887b..257ebaa 100644 --- a/latest_earthquake.go +++ b/latest_earthquake.go @@ -12,7 +12,7 @@ import ( ) func LatestEarthQuake() (*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/autogempa.json", BMKG_URL), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/autogempa.json", _BMKG), nil) if err != nil { return nil, err } @@ -79,7 +79,7 @@ func LatestEarthQuake() (*EarthQuakeData, error) { earthQuakeData.Potential = data.InfoGempa.Gempa.Potensi earthQuakeData.AffectedRegion = data.InfoGempa.Gempa.Dirasakan - earthQuakeData.Shakemap = fmt.Sprintf("%s/TEWS/%s", BMKG_URL, data.InfoGempa.Gempa.Shakemap) + earthQuakeData.Shakemap = fmt.Sprintf("%s/%s", _BMKG, data.InfoGempa.Gempa.Shakemap) return &earthQuakeData, nil } diff --git a/recents_earthquake.go b/recents_earthquake.go index 1d95af4..347e488 100644 --- a/recents_earthquake.go +++ b/recents_earthquake.go @@ -12,7 +12,7 @@ import ( ) func RecentsEarthQuake() ([]*EarthQuakeData, error) { - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/TEWS/gempaterkini.json", BMKG_URL), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/gempaterkini.json", _BMKG), nil) if err != nil { return nil, err }