Last active
December 24, 2023 08:04
-
-
Save guangrei/b71d5334774e58b7cbc5c3b81ca4d635 to your computer and use it in GitHub Desktop.
pengecekan hari libur dengan golang dan api hari libur v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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