Skip to content

Instantly share code, notes, and snippets.

@guangrei
Last active December 24, 2023 08:04
Show Gist options
  • Save guangrei/b71d5334774e58b7cbc5c3b81ca4d635 to your computer and use it in GitHub Desktop.
Save guangrei/b71d5334774e58b7cbc5c3b81ca4d635 to your computer and use it in GitHub Desktop.
pengecekan hari libur dengan golang dan api hari libur v2
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func holiday(date string) (string, error) {
resp, err := http.Get("https://raw.githubusercontent.com/guangrei/APIHariLibur_V2/main/holidays.json")
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var data map[string]map[string]string
if err := json.Unmarshal(body, &data); err != nil {
return "", err
}
if summary, ok := data[date]["summary"]; ok {
return summary, nil
}
return "", nil
}
func main() {
result, err := holiday("2023-06-01")
if err != nil {
fmt.Println("Error:", err)
return
}
if result == "" {
fmt.Println("Tidak libur!")
} else {
fmt.Println(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment