...
 
Commits (5)
......@@ -2,3 +2,4 @@ test.go
release
.vscode
docker/
*.out
......@@ -3,7 +3,7 @@ stages:
- docker_build
variables:
RELEASE_VERSION: "0.2.1"
RELEASE_VERSION: "0.3.1"
build:
stage: build
......@@ -27,12 +27,12 @@ docker_build:
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
- echo "$CI_JOB_TOKEN" | docker login --username gitlab-ci-token --password-stdin registry.gitlab.com
- docker build -t registry.gitlab.com/mradile/rssfeeder:$RELEASE_VERSION .
- docker push registry.gitlab.com/mradile/rssfeeder:$RELEASE_VERSION
- docker tag registry.gitlab.com/mradile/rssfeeder:$RELEASE_VERSION registry.gitlab.com/mradile/rssfeeder:latest
- docker push registry.gitlab.com/mradile/rssfeeder:latest
- echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_LOGIN" --password-stdin docker.io
- echo "$DOCKER_HUB_PASSWORD" | docker login --username "$DOCKER_HUB_LOGIN" --password-stdin docker.io
- docker tag registry.gitlab.com/mradile/rssfeeder:latest docker.io/mradile/rssfeeder:latest
- docker tag registry.gitlab.com/mradile/rssfeeder:$RELEASE_VERSION docker.io/mradile/rssfeeder:$RELEASE_VERSION
- docker push docker.io/mradile/rssfeeder:latest
......
0.2.1
\ No newline at end of file
0.3.1
\ No newline at end of file
......@@ -4,43 +4,22 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/docker-credential-helpers v0.6.1 h1:Dq4iIfcM7cNtddhLVWe9h4QDjsi4OER3Z8voPu/I52g=
github.com/docker/docker-credential-helpers v0.6.1/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/feeds v1.1.0 h1:pcgLJhbdYgaUESnj3AmXPcB7cS3vy63+jC/TI14AGXk=
github.com/gorilla/feeds v1.1.0/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/micro/cli v0.0.0-20180830071301-8b9d33ec2f19 h1:yYBEdLtvpHSezqBvUkGHJynuhgAek5Uew5P3RG7teQw=
github.com/micro/cli v0.0.0-20180830071301-8b9d33ec2f19/go.mod h1:x9x6qy+tXv17jzYWQup462+j3SIUgDa6vVTzU4IXy/w=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I=
github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.2.1 h1:bIcUwXqLseLF3BDAZduuNfekWG87ibtFxi59Bq+oI9M=
github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
......@@ -54,8 +33,3 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTu
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992 h1:BH3eQWeGbwRU2+wxxuuPOdFBmaiBH81O8BugSjHeTFg=
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
......@@ -11,6 +11,8 @@ import (
//RSSFeed represnts an RSS feed
type RSSFeed interface {
GetFeedAsAtomString() (string, error)
GetFeedAsRSSString() (string, error)
GetFeedAsJSONString() (string, error)
}
type rssFeed struct {
......@@ -22,6 +24,16 @@ func (rf *rssFeed) GetFeedAsAtomString() (string, error) {
return rf.feed.ToAtom()
}
//GetFeedAsRssString returns a RSS feed string
func (rf *rssFeed) GetFeedAsRSSString() (string, error) {
return rf.feed.ToRss()
}
//GetFeedAsRssString returns a JSON string
func (rf *rssFeed) GetFeedAsJSONString() (string, error) {
return rf.feed.ToJSON()
}
//Service return an RSSFeed instance for the given category
type Service interface {
GetFeed(category string) (RSSFeed, error)
......@@ -50,19 +62,26 @@ func (s *service) GetFeed(category string) (RSSFeed, error) {
if err != nil {
return nil, err
}
now := time.Now()
f := &feeds.Feed{
Title: fmt.Sprintf("RSS Feeder - %s", category),
Link: &feeds.Link{Href: s.serverURI},
Link: &feeds.Link{Href: s.serverURI + "/"},
Description: category,
Author: &feeds.Author{Name: "", Email: ""},
Created: time.Now(),
Author: &feeds.Author{Name: "rssfeeder"},
Created: now,
Updated: now,
}
for _, entry := range entries {
desc := entry.Description
if desc == "" {
desc = entry.URL
}
fi := &feeds.Item{
Title: entry.URL,
Link: &feeds.Link{Href: entry.URL},
Description: entry.Description,
Description: desc,
Author: &feeds.Author{Name: "", Email: ""},
Created: entry.Time,
Id: fmt.Sprintf("%s - %s", entry.Category, entry.URL),
......
......@@ -6,6 +6,8 @@ import (
"gitlab.com/mradile/rssfeeder/rssfeeder"
)
const extensions = "[atom,rss,json]"
//Service can list feeds
type Service interface {
ListFeeds() (*rssfeeder.FeedURLList, error)
......@@ -37,7 +39,7 @@ func (s *service) ListFeeds() (*rssfeeder.FeedURLList, error) {
list := make([]string, 0, len(cats))
for _, cat := range cats {
feedURL := fmt.Sprintf("%s/feed/%s/%s", s.serverURI, cat.Name, cat.URLToken)
feedURL := fmt.Sprintf("%s/feed/%s/%s.%s", s.serverURI, cat.Name, cat.URLToken, extensions)
list = append(list, feedURL)
}
......
......@@ -50,7 +50,7 @@ func NewHandler(config *Config, feeder feeding.Service, feedLister feedlisting.S
r.HandleFunc("/feeds", h.ValidateJWTToken(h.RSSFeeds)).Methods("GET")
r.HandleFunc("/feed/{category}/{token}", h.RSSFeed).Methods("GET")
r.HandleFunc("/feed/{category}/{token}.{ext}", h.RSSFeed).Methods("GET")
return h
}
......@@ -75,15 +75,29 @@ func (h *Handler) RSSFeed(w http.ResponseWriter, r *http.Request) {
return
}
xmlString, err := feed.GetFeedAsAtomString()
if err != nil {
jsonErrorResponse(w, http.StatusInternalServerError, err)
w.Header().Set("Content-Type", "application/xml")
var str string
var marshalErr error
switch vars["ext"] {
case "json":
str, marshalErr = feed.GetFeedAsJSONString()
w.Header().Set("Content-Type", "application/json")
case "rss":
str, marshalErr = feed.GetFeedAsRSSString()
case "atom":
str, marshalErr = feed.GetFeedAsAtomString()
default:
str, marshalErr = feed.GetFeedAsAtomString()
}
if marshalErr != nil {
jsonErrorResponse(w, http.StatusInternalServerError, marshalErr)
return
}
w.Header().Set("Content-Type", "application/rss+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(xmlString))
w.Write([]byte(str))
}
//AddFeedEntry adds a feed entry
......