summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-12-03 02:45:05 +0900
committerhaturatu <taro@eyes4you.org>2024-12-03 02:45:05 +0900
commitc136d742af273feabd5c5081fd90cca8ed3c0909 (patch)
treec82e4baddad26dc9afff527361468c2279c0785b
parent48ffae8ba35a571f212f3b4233d5320056520780 (diff)
space indent
-rw-r--r--main.go99
1 files changed, 50 insertions, 49 deletions
diff --git a/main.go b/main.go
index 8031dc1..bda7a75 100644
--- a/main.go
+++ b/main.go
@@ -9,62 +9,63 @@ import (
)
func fetchOGP(url string) (siteName string, title string, err error) {
- resp, err := http.Get(url)
- if err != nil {
- return "", "", fmt.Errorf("failed to fetch OGP URL: %w", err)
- }
- defer resp.Body.Close()
+ resp, err := http.Get(url)
+ if err != nil {
+ return "", "", fmt.Errorf("failed to fetch OGP URL: %w", err)
+ }
+ defer resp.Body.Close()
- doc, err := html.Parse(resp.Body)
- if err != nil {
- return "", "", fmt.Errorf("failed to parse HTML: %w", err)
- }
+ doc, err := html.Parse(resp.Body)
+ if err != nil {
+ return "", "", fmt.Errorf("failed to parse HTML: %w", err)
+ }
- var findOGP func(*html.Node)
- findOGP = func(n *html.Node) {
- if n.Type == html.ElementNode && n.Data == "meta" {
- var property, content string
- for _, attr := range n.Attr {
- if attr.Key == "property" {
- property = attr.Val
- } else if attr.Key == "content" {
- content = attr.Val
- }
- }
- switch property {
- case "og:site_name":
- siteName = content
- case "og:title":
- title = content
- }
- }
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- findOGP(c)
- }
- }
+ var findOGP func(*html.Node)
+ findOGP = func(n *html.Node) {
+ if n.Type == html.ElementNode && n.Data == "meta" {
+ var property, content string
+ for _, attr := range n.Attr {
+ if attr.Key == "property" {
+ property = attr.Val
+ } else if attr.Key == "content" {
+ content = attr.Val
+ }
+ }
+ switch property {
+ case "og:site_name":
+ siteName = content
+ case "og:title":
+ title = content
+ }
+ }
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
+ findOGP(c)
+ }
+ }
- findOGP(doc)
+ findOGP(doc)
- if siteName == "" && title == "" {
- return "", "",
- fmt.Errorf("OGP data none")
- }
- return siteName, title, nil
+ if siteName == "" && title == "" {
+ return "", "",
+ fmt.Errorf("OGP data none")
+ }
+ return siteName, title, nil
}
func main() {
- if len(os.Args) < 2 {
- fmt.Println("Usage: go run main.go https://soulminingrig.com/")
- return
- }
+ if len(os.Args) < 2 {
+ fmt.Println("Usage: go run main.go https://soulminingrig.com/")
+ return
+ }
- url := os.Args[1]
- siteName, title, err := fetchOGP(url)
- if err != nil {
- fmt.Printf("Error: %v\n", err)
- return
- }
+ url := os.Args[1]
+ siteName, title, err := fetchOGP(url)
+ if err != nil {
+ fmt.Printf("Error: %v\n", err)
+ return
+ }
- fmt.Printf("Site Name: %s\n", siteName)
- fmt.Printf("Title: %s\n", title)
+ fmt.Printf("Site Name: %s\n", siteName)
+ fmt.Printf("aaaaa:: %s\n", siteName)
+ fmt.Printf("Title: %s\n", title)
}