Skip to content

Commit

Permalink
update go modules, GitHub CI actions, migrate to lcw v2 with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Feb 20, 2024
1 parent 8bd8927 commit faf39bb
Show file tree
Hide file tree
Showing 504 changed files with 20,280 additions and 22,090 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:

steps:
- name: set up go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20"
id: go

- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: build and test
run: |
Expand All @@ -28,10 +28,9 @@ jobs:
env:
GO111MODULE: on
TZ: "America/Chicago"
GOFLAGS: "-mod=vendor"

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest

Expand All @@ -43,11 +42,11 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
Expand Down
19 changes: 7 additions & 12 deletions app/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/render"
"github.com/go-pkgz/lcw"
"github.com/go-pkgz/lcw/v2"
log "github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"github.com/go-pkgz/rest/logger"
Expand All @@ -46,7 +46,7 @@ type Server struct {
AdminPasswd string

httpServer *http.Server
cache lcw.LoadingCache
cache lcw.LoadingCache[[]byte]
templates *template.Template
}

Expand All @@ -71,7 +71,8 @@ type YoutubeStore interface {
func (s *Server) Run(ctx context.Context, port int) {
log.Printf("[INFO] starting server on port %d", port)
var err error
if s.cache, err = lcw.NewExpirableCache(lcw.TTL(time.Minute*3), lcw.MaxCacheSize(10*1024*1024)); err != nil {
o := lcw.NewOpts[[]byte]()
if s.cache, err = lcw.NewExpirableCache(o.TTL(time.Minute*3), o.MaxCacheSize(10*1024*1024)); err != nil {
log.Printf("[PANIC] failed to make loading cache, %v", err)
return
}
Expand Down Expand Up @@ -182,7 +183,7 @@ func (s *Server) router() *chi.Mux {
func (s *Server) getFeedCtrl(w http.ResponseWriter, r *http.Request) {
feedName := chi.URLParam(r, "name")

data, err := s.cache.Get("feed::"+feedName, func() (interface{}, error) {
data, err := s.cache.Get("feed::"+feedName, func() ([]byte, error) {
items, err := s.Store.Load(feedName, s.Conf.System.MaxTotal, true)
if err != nil {
return nil, err
Expand Down Expand Up @@ -238,22 +239,16 @@ func (s *Server) getFeedCtrl(w http.ResponseWriter, r *http.Request) {
res = strings.Replace(res, "<duration>", "<itunes:duration>", -1)
res = strings.Replace(res, "</duration>", "</itunes:duration>", -1)

return res, nil
return []byte(res), nil
})

if err != nil {
rest.SendErrorJSON(w, r, log.Default(), http.StatusBadRequest, err, "failed to get feed")
return
}

res, ok := data.(string)
if !ok {
rest.SendErrorJSON(w, r, log.Default(), http.StatusInternalServerError, err, "failed to convert feed")
return
}

w.Header().Set("Content-Type", "application/xml; charset=UTF-8")
_, _ = fmt.Fprintf(w, "%s", res)
_, _ = fmt.Fprintf(w, "%s", data)
}

// GET /image/{name}
Expand Down
10 changes: 5 additions & 5 deletions app/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

"github.com/go-pkgz/lcw"
"github.com/go-pkgz/lcw/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -75,7 +75,7 @@ func TestServer_getFeedCtrl(t *testing.T) {
Version: "1.0",
TemplLocation: "../webapp/templates/*",
Store: store,
cache: lcw.NewNopCache(),
cache: lcw.NewNopCache[[]byte](),
Conf: config.Conf{
Feeds: map[string]config.Feed{
"feed1": {
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestServer_getFeedCtrlExtendDateTitle(t *testing.T) {
Version: "1.0",
TemplLocation: "../webapp/templates/*",
Store: store,
cache: lcw.NewNopCache(),
cache: lcw.NewNopCache[[]byte](),
Conf: config.Conf{
Feeds: map[string]config.Feed{
"feed1": {
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestServer_getFeedCtrlFeedImage(t *testing.T) {
Version: "1.0",
TemplLocation: "../webapp/templates/*",
Store: store,
cache: lcw.NewNopCache(),
cache: lcw.NewNopCache[[]byte](),
Conf: config.Conf{
Feeds: map[string]config.Feed{
"feed1": {
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestServer_configCtrl(t *testing.T) {
Version: "1.0",
TemplLocation: "../webapp/templates/*",
Store: store,
cache: lcw.NewNopCache(),
cache: lcw.NewNopCache[[]byte](),
Conf: config.Conf{
Feeds: map[string]config.Feed{
"feed1": {
Expand Down
20 changes: 10 additions & 10 deletions app/api/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func (s *Server) getFeedPageCtrl(w http.ResponseWriter, r *http.Request) {
feedName := chi.URLParam(r, "name")

data, err := s.cache.Get(feedName, func() (interface{}, error) {
data, err := s.cache.Get(feedName, func() ([]byte, error) {
items, err := s.Store.Load(feedName, s.Conf.System.MaxTotal, false)
if err != nil {
return nil, err
Expand Down Expand Up @@ -79,7 +79,7 @@ func (s *Server) getFeedPageCtrl(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data.([]byte)) // nolint
_, _ = w.Write(data) // nolint
}

// GET /feed/{name}/source/{source} - renders feed's source page with list of items
Expand All @@ -94,7 +94,7 @@ func (s *Server) getFeedSourceCtrl(w http.ResponseWriter, r *http.Request) {
return
}

data, err := s.cache.Get(feedName+sourceName, func() (interface{}, error) {
data, err := s.cache.Get(feedName+sourceName, func() ([]byte, error) {
if _, ok := s.Conf.Feeds[feedName]; !ok {
return nil, fmt.Errorf("feed %s not found", feedName)
}
Expand Down Expand Up @@ -160,12 +160,12 @@ func (s *Server) getFeedSourceCtrl(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data.([]byte)) // nolint
_, _ = w.Write(data) // nolint
}

// GET /feeds - renders page with list of feeds
func (s *Server) getFeedsPageCtrl(w http.ResponseWriter, r *http.Request) {
data, err := s.cache.Get("feeds", func() (interface{}, error) {
data, err := s.cache.Get("feeds", func() ([]byte, error) {

feeds := s.feeds()

Expand Down Expand Up @@ -213,12 +213,12 @@ func (s *Server) getFeedsPageCtrl(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data.([]byte)) // nolint
_, _ = w.Write(data) // nolint
}

// GET /yt/channels - renders page with list of YouTube channels
func (s *Server) getYoutubeChannelsPageCtrl(w http.ResponseWriter, r *http.Request) {
data, err := s.cache.Get("channels", func() (interface{}, error) {
data, err := s.cache.Get("channels", func() ([]byte, error) {
type channelItem struct {
youtube.FeedInfo
ChannelURL string
Expand Down Expand Up @@ -265,13 +265,13 @@ func (s *Server) getYoutubeChannelsPageCtrl(w http.ResponseWriter, r *http.Reque

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data.([]byte)) // nolint
_, _ = w.Write(data) // nolint
}

// GET /feed/{name}/sources - renders page with feed's list of sources
func (s *Server) getSourcesPageCtrl(w http.ResponseWriter, r *http.Request) {
feedName := chi.URLParam(r, "name")
data, err := s.cache.Get(feedName+"-sources", func() (interface{}, error) {
data, err := s.cache.Get(feedName+"-sources", func() ([]byte, error) {
if _, ok := s.Conf.Feeds[feedName]; !ok {
return nil, fmt.Errorf("feed %s not found", feedName)
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (s *Server) getSourcesPageCtrl(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(data.([]byte)) // nolint
_, _ = w.Write(data) // nolint
}

func (s *Server) renderErrorPage(w http.ResponseWriter, r *http.Request, err error, errCode int) { // nolint
Expand Down
2 changes: 1 addition & 1 deletion app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"time"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/umputun/feed-master/app/feed"
"github.com/umputun/feed-master/app/youtube"
Expand Down
41 changes: 22 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/umputun/feed-master

go 1.20
go 1.21

require (
github.com/ChimeraCoder/anaconda v2.0.0+incompatible
Expand All @@ -9,44 +9,47 @@ require (
github.com/didip/tollbooth/v7 v7.0.1
github.com/didip/tollbooth_chi v0.0.0-20220719025231-d662a7f6928f
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/chi/v5 v5.0.10
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/render v1.0.3
github.com/go-pkgz/lcw v1.0.2
github.com/go-pkgz/lgr v0.11.0
github.com/go-pkgz/lcw/v2 v2.0.0
github.com/go-pkgz/lgr v0.11.1
github.com/go-pkgz/repeater v1.1.3
github.com/go-pkgz/rest v1.17.0
github.com/go-pkgz/rest v1.19.0
github.com/go-pkgz/syncs v1.3.2
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jessevdk/go-flags v1.5.0
github.com/microcosm-cc/bluemonday v1.0.25
github.com/microcosm-cc/bluemonday v1.0.26
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/tcolgate/mp3 v0.0.0-20170426193717-e79c5a46d300
go.etcd.io/bbolt v1.3.7
golang.org/x/net v0.17.0
go.etcd.io/bbolt v1.3.8
golang.org/x/net v0.21.0
gopkg.in/tucnak/telebot.v2 v2.5.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/ChimeraCoder/tokenbucket v0.0.0-20131201223612-c5a927568de7 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/azr/backoff v0.0.0-20160115115103-53511d3c7330 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-jsonpointer v0.0.0-20160814072949-ba0abeacc3dc // indirect
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 // indirect
github.com/go-pkgz/expirable-cache v0.1.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/go-pkgz/expirable-cache v1.0.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading

0 comments on commit faf39bb

Please sign in to comment.