Skip to content

Commit

Permalink
feat: impl serve rss
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 25, 2024
1 parent aa6f98d commit ea4d975
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ bin/

dist/
.release-env
*.db
*.db

.golangci.yml
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SHELL:=/bin/bash
LINT_FILE_TAG=v0.2.0
LINT_FILE_TAG=master
LINT_FILE_URL=https://raw.githubusercontent.com/tuihub/librarian/$(LINT_FILE_TAG)/.golangci.yml
LINT_FILE_LOCAL=.golangci.yml

GOLANG_CROSS_VERSION ?= latest
PACKAGE_NAME := github.com/tuihub/tuihub-rss
Expand All @@ -10,13 +11,14 @@ PROTO_VERSION=$(shell go list -m -f '{{.Version}}' github.com/tuihub/protos)
.PHONY: init
# init env
init:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: lint
# lint files
lint:
golangci-lint run --fix -c <(curl -sSL $(LINT_FILE_URL))
golangci-lint run -c <(curl -sSL $(LINT_FILE_URL)) # re-run to make sure fixes are valid, useful in some condition
curl -sSL $(LINT_FILE_URL) -o $(LINT_FILE_LOCAL)
golangci-lint run --fix -c $(LINT_FILE_LOCAL)
golangci-lint run -c $(LINT_FILE_LOCAL) # re-run to make sure fixes are valid, useful in some condition

.PHONY: release-dry-run
# build server in release mode, for manual test
Expand Down
36 changes: 33 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ var (
version string
)

const (
rssServerURLPrefix = "RSS_SERVER_URL_PREFIX"
rssServerHost = "RSS_SERVER_HOST"
rssServerPort = "RSS_SERVER_PORT"
)

func main() {
config := &porter.GetPorterInformationResponse{
BinarySummary: &librarian.PorterBinarySummary{
Expand All @@ -29,7 +35,7 @@ func main() {
},
GlobalName: "github.com/tuihub/tuihub-rss",
Region: "",
FeatureSummary: &porter.PorterFeatureSummary{ //nolint:exhaustruct // no need
FeatureSummary: &librarian.FeatureSummary{ //nolint:exhaustruct // no need
FeedSources: []*librarian.FeatureFlag{
{
Id: tuihub.WellKnownToString(librarian.WellKnownFeedSource_WELL_KNOWN_FEED_SOURCE_RSS),
Expand All @@ -38,19 +44,43 @@ func main() {
ConfigJsonSchema: tuihub.MustReflectJSONSchema(new(internal.PullRSSConfig)),
},
},
NotifyDestinations: []*librarian.FeatureFlag{
{
Id: tuihub.WellKnownToString(librarian.WellKnownFeedSource_WELL_KNOWN_FEED_SOURCE_RSS),
Name: "RSS",
Description: "",
ConfigJsonSchema: tuihub.MustReflectJSONSchema(new(internal.ServeRSSConfig)),
Extra: map[string]string{
"URLPrefix": os.Getenv(rssServerURLPrefix),
},
},
},
},
ContextJsonSchema: nil,
}
server, err := tuihub.NewPorter(
porterServer, err := tuihub.NewPorter(
context.Background(),
config,
internal.NewHandler(),
tuihub.WithAsUser(),
)
if err != nil {
logger.Error(err)
os.Exit(1)
}
if err = server.Run(); err != nil {
rssServer, err := internal.NewServer(porterServer)
if err != nil {
logger.Error(err)
os.Exit(1)
}
go func() {
err = rssServer.Run(os.Getenv(rssServerHost) + ":" + os.Getenv(rssServerPort))
if err != nil {
logger.Error(err)
os.Exit(1)
}
}()
if err = porterServer.Run(); err != nil {
logger.Error(err)
os.Exit(1)
}
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ toolchain go1.21.12
require (
github.com/go-kratos/kratos/v2 v2.8.0
github.com/gocolly/colly/v2 v2.1.1-0.20231020184023-3c987f1982ed
github.com/gorilla/feeds v1.2.0
github.com/mmcdole/gofeed v1.3.0
github.com/muzhou233/go-favicon v0.1.1
github.com/stretchr/testify v1.8.4
github.com/tuihub/protos v0.4.20
github.com/tuihub/tuihub-go v0.0.13
github.com/tuihub/protos v0.4.23
github.com/tuihub/tuihub-go v0.0.15
google.golang.org/protobuf v1.34.2
)

Expand Down Expand Up @@ -70,6 +71,6 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/grpc v1.66.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
23 changes: 14 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.12.0 h1:4X+VP1GHd1Mhj6IB5mMeGbLCleqxjletLK6K0rbxyZI=
github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0=
github.com/envoyproxy/go-control-plane v0.12.1-0.20240621013728-1eb8caab5155 h1:IgJPqnrlY2Mr4pYB6oaMKvFvwJ9H+X6CCY5x1vCTcpc=
github.com/envoyproxy/go-control-plane v0.12.1-0.20240621013728-1eb8caab5155/go.mod h1:5Wkq+JduFtdAXihLmeTJf+tRYIT4KBc2vPXDhwVo1pA=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
Expand Down Expand Up @@ -119,6 +119,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/feeds v1.2.0 h1:O6pBiXJ5JHhPvqy53NsjKOThq+dNFm8+DFrxBEdzSCc=
github.com/gorilla/feeds v1.2.0/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/hashicorp/consul/api v1.29.1 h1:UEwOjYJrd3lG1x5w7HxDRMGiAUPrb3f103EoeKuuEcc=
Expand Down Expand Up @@ -184,8 +186,9 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down Expand Up @@ -239,6 +242,8 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -280,10 +285,10 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
github.com/tuihub/protos v0.4.20 h1:fozd8I6uRS1250YqmX7a26mFR/xUQPp4YAB0pqJoFZU=
github.com/tuihub/protos v0.4.20/go.mod h1:btbip/Tx2/xwrCuD/+pk7F/ElXhUYhjm8Dv2+uhd58o=
github.com/tuihub/tuihub-go v0.0.13 h1:9+eUsHGc7rMEDqXulS8A45nJp3b4djuRDARORVd+IJk=
github.com/tuihub/tuihub-go v0.0.13/go.mod h1:gosLab0d+gjy93N61zfCdY1YfELjDh5u/tNs3hXSodI=
github.com/tuihub/protos v0.4.23 h1:qKRxguvvVbDNBPItSB3dGYxpz+lsex2sZDXt2NyT8rE=
github.com/tuihub/protos v0.4.23/go.mod h1:lmf29LH3wf7Fb0in47Q/ar2qf2V7ogckV6dnlBrsZ1I=
github.com/tuihub/tuihub-go v0.0.15 h1:eXMi9lyDVg5p2cOzFBUe3gNZlrsI7tZnxrgVAWY9jRc=
github.com/tuihub/tuihub-go v0.0.15/go.mod h1:WB0TZKRtY9/RI+nLM34I+tPrJZ7f+TMMnAbW0Phedh8=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
Expand Down Expand Up @@ -426,8 +431,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
41 changes: 32 additions & 9 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

librarian "github.com/tuihub/protos/pkg/librarian/v1"

"github.com/gorilla/feeds"
"github.com/mmcdole/gofeed"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand All @@ -17,23 +18,38 @@ import (
// goverter:output:package github.com/tuihub/tuihub-rss/internal/converter
// goverter:matchIgnoreCase
// goverter:ignoreUnexported
// goverter:extend ToPBTime
// goverter:extend FromPBTime
type Converter interface {
// goverter:matchIgnoreCase
// goverter:ignore Id
ToPBFeed(t *gofeed.Feed) *librarian.Feed
// goverter:matchIgnoreCase
// goverter:ignore Id
// goverter:map UpdatedParsed | ToPBTime
// goverter:map PublishedParsed | ToPBTime
// goverter:ignore PublishPlatform
// goverter:ignore ReadCount
ToPBFeedItem(t *gofeed.Item) *librarian.FeedItem

// goverter:matchIgnoreCase
ToPBFeedImage(t *gofeed.Image) *librarian.FeedImage

// goverter:matchIgnoreCase
ToPBFeedEnclosure(t *gofeed.Enclosure) *librarian.FeedEnclosure
// goverter:ignore Id
// goverter:ignore Link
// goverter:ignore Author
// goverter:ignore Updated
// goverter:ignore Created
// goverter:ignore Subtitle
// goverter:ignore Copyright
FromPBFeed(t *librarian.Feed) *feeds.Feed
// goverter:ignore Id
// goverter:ignore Link
// goverter:ignore Source
// goverter:ignore Author
// goverter:ignore IsPermaLink
// goverter:map UpdatedParsed Updated
// goverter:map PublishedParsed Created
// goverter:ignore Enclosure
FromPBFeedItem(t *librarian.FeedItem) *feeds.Item
FromPBFeedItems(t []*librarian.FeedItem) []*feeds.Item
// goverter:ignore Link
// goverter:ignore Width
// goverter:ignore Height
FromPBFeedImage(t *librarian.FeedImage) *feeds.Image
}

func ToPBTime(t *time.Time) *timestamppb.Timestamp {
Expand All @@ -42,3 +58,10 @@ func ToPBTime(t *time.Time) *timestamppb.Timestamp {
}
return timestamppb.New(*t)
}

func FromPBTime(t *timestamppb.Timestamp) time.Time {
if t == nil {
return time.Time{}
}
return t.AsTime()
}
94 changes: 70 additions & 24 deletions internal/converter/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea4d975

Please sign in to comment.