0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

golangメモ

Last updated at Posted at 2021-07-29

開発環境作成

バージョン
go version go1.16.5 linux/amd64

一回目に起動する

docker run -it --name golang--workdir /working -v $PWD:/working golang bash     

2回目に起動する

docker start golang -i

#プロジェクトの初期化

go mod init sample

#実行ファイルの作成

sample.go
package main

import (
    "fmt"
    "os"
    "time"

    "github.com/mmcdole/gofeed"
)

func main() {
    feed, err := gofeed.NewParser().ParseURL("https://zenn.dev/spiegel/feed")
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    fmt.Println(feed.Title)
    fmt.Println(feed.FeedType, feed.FeedVersion)
    for _, item := range feed.Items {
        if item == nil {
            break
        }
        fmt.Println(item.Title)
        fmt.Println("\t->", item.Link)
        fmt.Println("\t->", item.PublishedParsed.Format(time.RFC3339))
    }
}

#モジュールのインストール
goにはGOPATHモードとモジュール対応モードがあり、デフォルトのモジュール対応モードを使う。

go mod tidy

#実行

go run sample.go

参考

https://hisa-web.net/archives/1056
https://zenn.dev/spiegel/articles/20201003-feed-with-golang

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?