File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ atom *
Original file line number Diff line number Diff line change 1+ version : ' 3'
2+
3+ tasks :
4+ default :
5+ cmds :
6+ - task : run
7+ install-lib :
8+ cmds :
9+ - go install golang.org/x/tools/cmd/goimports@latest
10+ - go install honnef.co/go/tools/cmd/staticcheck@latest
11+ build :
12+ deps : [ install-lib ]
13+ cmds :
14+ - goimports -w .
15+ - go vet
16+ - staticcheck
17+ - go build
18+ run :
19+ deps : [ build ]
20+ cmds :
21+ - ./atom
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "encoding/xml"
5+ "fmt"
6+ "io"
7+ "net/http"
8+ )
9+
10+ type (
11+ Feed struct {
12+ XMLName xml.Name `xml:"feed"`
13+ Titles []string `xml:"entry>title"`
14+ }
15+ )
16+
17+ const (
18+ URL = "https://devlights.hatenablog.com/feed"
19+ )
20+
21+ func panicOnErr [T any ](v T , err error ) T {
22+ if err != nil {
23+ panic (err )
24+ }
25+
26+ return v
27+ }
28+
29+ // ブログ [いろいろ備忘録日記](https://devlights.hatenablog.com/) から Atom Feed を取得して表示するサンプルです。
30+ //
31+ // REFERENCES:
32+ // - https://qiita.com/you8/items/e903fd463cf770688e1e
33+ func main () {
34+ fmt .Printf ("[URL] %s\n " , URL )
35+
36+ resp := panicOnErr (http .Get (URL ))
37+ body := panicOnErr (io .ReadAll (resp .Body ))
38+ defer resp .Body .Close ()
39+
40+ var feed Feed
41+ if err := xml .Unmarshal (body , & feed ); err != nil {
42+ panic (err )
43+ }
44+
45+ for i , title := range feed .Titles {
46+ fmt .Printf ("[%2d] %s\n " , i + 1 , title )
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments