diff --git a/affected_earthquake.go b/affected_earthquake.go index 3bb519a..7bf197d 100644 --- a/affected_earthquake.go +++ b/affected_earthquake.go @@ -3,6 +3,7 @@ package gempago import ( "encoding/json" "errors" + "fmt" "io" "net/http" "strconv" @@ -10,8 +11,10 @@ import ( "time" ) +// TODO add exponential backoff algorithm + 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/gempadirasakan.json", _BMKG), nil) if err != nil { return nil, err } diff --git a/const.go b/const.go new file mode 100644 index 0000000..e4a41f9 --- /dev/null +++ b/const.go @@ -0,0 +1,6 @@ +package gempago + +const ( + _BMKG = "https://data.bmkg.go.id/DataMKG/TEWS" + _USGS = "" +) 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..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, "https://data.bmkg.go.id/DataMKG/TEWS/autogempa.json", 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("https://data.bmkg.go.id/DataMKG/TEWS/%s", 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 12ab5e5..347e488 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/gempaterkini.json", _BMKG), nil) if err != nil { return nil, err }