Go 언어로 RSS 시드 생성

1376 단어 GoRSStech

RSS 피드 내보내기(xml) 내용


package main

import (
    "fmt"
    "log"
    "time"
    "github.com/gorilla/feeds"
)

func main() {
    now := time.Now()
    feed := &feeds.Feed{
        Title:       "ブログタイトル",
        Link:        &feeds.Link{Href: "http://hoge.com/blog"},
        Description: "ブログの詳細",
        Author:      &feeds.Author{Name: "ohnishi", Email: "[email protected]"},
        Created:     now,
    }

    feed.Items = []*feeds.Item{
        &feeds.Item{
            Title:       "記事タイトル1",
            Link:        &feeds.Link{Href: "http://hoge.com/blog/article1"},
            Description: "記事の詳細1",
            Created:     now,
        },
        &feeds.Item{
            Title:       "記事タイトル2",
            Link:        &feeds.Link{Href: "http://hoge.com/blog/article2"},
            Description: "記事の詳細2",
            Created:     now,
        },
    }

    atom, err := feed.ToAtom()
    if err != nil {
        log.Fatal(err)
    }

    rss, err := feed.ToRss()
    if err != nil {
        log.Fatal(err)
    }

    json, err := feed.ToJSON()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(atom, "\n", rss, "\n", json)
}

좋은 웹페이지 즐겨찾기