Skip to content

Commit

Permalink
add golangci and lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips committed Aug 26, 2019
1 parent 86ff867 commit e0b1635
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 27 deletions.
99 changes: 99 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
run:
concurrency: 6
deadline: 5m
skip-files:
- ".*_test\\.go"
- "lib/.*"
linters:
disable-all: true
enable:
- deadcode
- depguard
- dupl
- goconst
- gocritic
- gofmt
- goimports
- golint
- govet
- ineffassign
- misspell
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- varcheck
- gocyclo
linters-settings:
gocritic:
enabled-checks:
# Diagnostic
- argOrder
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagDeref
- flagName
- nilValReturn
- offBy1
- weakCond
#- appendAssign
- octalLiteral
- sloppyReassign

# Performance
- equalFold
#- hugeParam
- indexAlloc
- rangeExprCopy
#- rangeValCopy
- appendCombine

# Style
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- emptyStringTest
- hexLiteral
#- ifElseChain
- methodExprCall
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- yodaStyleExpr
- wrapperFunc

# Opinionated
- initClause
- nestingReduce
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
#- builtinShadow
#- importShadow
- paramTypeCombine
#- unnamedResult
4 changes: 2 additions & 2 deletions cmd/escapepod/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ var serveCmd = &cobra.Command{
}
}()

// gracefull shutdown
sigChan := make(chan os.Signal)
// graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan

Expand Down
6 changes: 3 additions & 3 deletions pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type Job struct {
}

/// Crawler
// Crawler
type Crawler struct {
db *gorm.DB
workerChan chan *Job
Expand All @@ -29,7 +29,7 @@ func NewCrawler(db *gorm.DB) *Crawler {
return crawler
}

/// Run intended to be run from a go routine
// Run intended to be run from a go routine
func (c *Crawler) Run(concurrency int, stopCh <-chan struct{}) {
go c.Scheduler(stopCh)
for i := 0; i < concurrency; i++ {
Expand All @@ -38,7 +38,7 @@ func (c *Crawler) Run(concurrency int, stopCh <-chan struct{}) {
<-stopCh
}

/// Scheduler intended to be run from a goroutine
// Scheduler intended to be run from a goroutine
func (c *Crawler) Scheduler(stopCh <-chan struct{}) {
log.Debug("Starting scheduler")
defer log.Debug("Stopping scheduler")
Expand Down
13 changes: 3 additions & 10 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@ import (
"strings"

"github.com/jinzhu/gorm"
// import postgres
_ "github.com/jinzhu/gorm/dialects/postgres"
// import sqlite
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/labstack/gommon/log"
"github.com/spf13/viper"

"github.com/rphillips/escapepod/pkg/models"
)

type DBParams struct {
Host string
Port int
User string
Password string
DBName string
SSLMode string
}

func openPostgres(dbURL string) (*gorm.DB, error) {
if len(dbURL) == 0 {
if dbURL == "" {
dbURL = strings.Join([]string{
"host=" + viper.GetString("db.host"),
"port=" + viper.GetString("db.port"),
Expand Down
8 changes: 6 additions & 2 deletions pkg/handlers/podcasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ func PodcastsImport(c echo.Context) error {
if err != nil {
return c.JSON(http.StatusBadRequest, err)
}
go importFromOPML(app, parsed)
go func() {
if err := importFromOPML(app, parsed); err != nil {
c.Logger().Errorf("could not import OPML: %v", err)
}
}()
return c.JSON(http.StatusOK, "OK")
}

func importFromOPML(app *app.App, o *opml.OPML) error {
if len(o.Body.Outline) <= 0 {
if len(o.Body.Outline) == 0 {
return fmt.Errorf("invalid opml")
}
if o.Body.Outline[0].Text != "feeds" {
Expand Down
7 changes: 5 additions & 2 deletions pkg/models/podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"bytes"
"image"
"image/jpeg"

// import png to support png
_ "image/png"

"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -36,8 +39,8 @@ type Podcast struct {
func (p *Podcast) Crawl() error {
parser := gofeed.NewParser()
var feed *gofeed.Feed
if strings.HasPrefix("file://", *p.FeedURL) {
fileData, err := ioutil.ReadFile(strings.TrimPrefix("file://", *p.FeedURL))
if strings.HasPrefix(*p.FeedURL, "file://") {
fileData, err := ioutil.ReadFile(strings.TrimPrefix(*p.FeedURL, "file://"))
if err != nil {
return err
}
Expand Down
14 changes: 6 additions & 8 deletions pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ func RegisterRoutes(r *echo.Echo, fs stuffbin.FileSystem) {
r.GET("/*", echo.WrapHandler(fs.FileServer()))

api := r.Group("/api/v1")
{
api.POST("/podcasts", handlers.PodcastsCreate)
api.POST("/podcasts/import", handlers.PodcastsImport)
api.GET("/podcasts", handlers.PodcastsList)
api.GET("/podcasts/:id", handlers.PodcastsGet)
api.GET("/podcasts/:id/episodes", handlers.PodcastsGetEpisodes)
api.GET("/podcasts/:id/image", handlers.PodcastsImageGet)
}
api.POST("/podcasts", handlers.PodcastsCreate)
api.POST("/podcasts/import", handlers.PodcastsImport)
api.GET("/podcasts", handlers.PodcastsList)
api.GET("/podcasts/:id", handlers.PodcastsGet)
api.GET("/podcasts/:id/episodes", handlers.PodcastsGetEpisodes)
api.GET("/podcasts/:id/image", handlers.PodcastsImageGet)
}

func handleIndexPage(c echo.Context) error {
Expand Down

0 comments on commit e0b1635

Please sign in to comment.