Skip to content

Commit e0b1635

Browse files
committed
add golangci and lint files
1 parent 86ff867 commit e0b1635

File tree

7 files changed

+124
-27
lines changed

7 files changed

+124
-27
lines changed

.golangci.yml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
run:
3+
concurrency: 6
4+
deadline: 5m
5+
skip-files:
6+
- ".*_test\\.go"
7+
- "lib/.*"
8+
linters:
9+
disable-all: true
10+
enable:
11+
- deadcode
12+
- depguard
13+
- dupl
14+
- goconst
15+
- gocritic
16+
- gofmt
17+
- goimports
18+
- golint
19+
- govet
20+
- ineffassign
21+
- misspell
22+
- staticcheck
23+
- structcheck
24+
- typecheck
25+
- unconvert
26+
- unparam
27+
- varcheck
28+
- gocyclo
29+
linters-settings:
30+
gocritic:
31+
enabled-checks:
32+
# Diagnostic
33+
- argOrder
34+
- badCond
35+
- caseOrder
36+
- codegenComment
37+
- commentedOutCode
38+
- deprecatedComment
39+
- dupArg
40+
- dupBranchBody
41+
- dupCase
42+
- dupSubExpr
43+
- exitAfterDefer
44+
- flagDeref
45+
- flagName
46+
- nilValReturn
47+
- offBy1
48+
- weakCond
49+
#- appendAssign
50+
- octalLiteral
51+
- sloppyReassign
52+
53+
# Performance
54+
- equalFold
55+
#- hugeParam
56+
- indexAlloc
57+
- rangeExprCopy
58+
#- rangeValCopy
59+
- appendCombine
60+
61+
# Style
62+
- assignOp
63+
- boolExprSimplify
64+
- captLocal
65+
- commentFormatting
66+
- commentedOutImport
67+
- defaultCaseOrder
68+
- docStub
69+
- elseif
70+
- emptyFallthrough
71+
- emptyStringTest
72+
- hexLiteral
73+
#- ifElseChain
74+
- methodExprCall
75+
- regexpMust
76+
- singleCaseSwitch
77+
- sloppyLen
78+
- stringXbytes
79+
- switchTrue
80+
- typeAssertChain
81+
- typeSwitchVar
82+
- underef
83+
- unlabelStmt
84+
- unlambda
85+
- unslice
86+
- valSwap
87+
- yodaStyleExpr
88+
- wrapperFunc
89+
90+
# Opinionated
91+
- initClause
92+
- nestingReduce
93+
- ptrToRefParam
94+
- typeUnparen
95+
- unnecessaryBlock
96+
#- builtinShadow
97+
#- importShadow
98+
- paramTypeCombine
99+
#- unnamedResult

cmd/escapepod/serve.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ var serveCmd = &cobra.Command{
7878
}
7979
}()
8080

81-
// gracefull shutdown
82-
sigChan := make(chan os.Signal)
81+
// graceful shutdown
82+
sigChan := make(chan os.Signal, 1)
8383
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
8484
<-sigChan
8585

pkg/crawler/crawler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type Job struct {
1212
}
1313

14-
/// Crawler
14+
// Crawler
1515
type Crawler struct {
1616
db *gorm.DB
1717
workerChan chan *Job
@@ -29,7 +29,7 @@ func NewCrawler(db *gorm.DB) *Crawler {
2929
return crawler
3030
}
3131

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

41-
/// Scheduler intended to be run from a goroutine
41+
// Scheduler intended to be run from a goroutine
4242
func (c *Crawler) Scheduler(stopCh <-chan struct{}) {
4343
log.Debug("Starting scheduler")
4444
defer log.Debug("Stopping scheduler")

pkg/db/db.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@ import (
55
"strings"
66

77
"github.com/jinzhu/gorm"
8+
// import postgres
89
_ "github.com/jinzhu/gorm/dialects/postgres"
10+
// import sqlite
911
_ "github.com/jinzhu/gorm/dialects/sqlite"
1012
"github.com/labstack/gommon/log"
1113
"github.com/spf13/viper"
1214

1315
"github.com/rphillips/escapepod/pkg/models"
1416
)
1517

16-
type DBParams struct {
17-
Host string
18-
Port int
19-
User string
20-
Password string
21-
DBName string
22-
SSLMode string
23-
}
24-
2518
func openPostgres(dbURL string) (*gorm.DB, error) {
26-
if len(dbURL) == 0 {
19+
if dbURL == "" {
2720
dbURL = strings.Join([]string{
2821
"host=" + viper.GetString("db.host"),
2922
"port=" + viper.GetString("db.port"),

pkg/handlers/podcasts.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ func PodcastsImport(c echo.Context) error {
8383
if err != nil {
8484
return c.JSON(http.StatusBadRequest, err)
8585
}
86-
go importFromOPML(app, parsed)
86+
go func() {
87+
if err := importFromOPML(app, parsed); err != nil {
88+
c.Logger().Errorf("could not import OPML: %v", err)
89+
}
90+
}()
8791
return c.JSON(http.StatusOK, "OK")
8892
}
8993

9094
func importFromOPML(app *app.App, o *opml.OPML) error {
91-
if len(o.Body.Outline) <= 0 {
95+
if len(o.Body.Outline) == 0 {
9296
return fmt.Errorf("invalid opml")
9397
}
9498
if o.Body.Outline[0].Text != "feeds" {

pkg/models/podcast.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
"bytes"
66
"image"
77
"image/jpeg"
8+
9+
// import png to support png
810
_ "image/png"
11+
912
"io"
1013
"io/ioutil"
1114
"net/http"
@@ -36,8 +39,8 @@ type Podcast struct {
3639
func (p *Podcast) Crawl() error {
3740
parser := gofeed.NewParser()
3841
var feed *gofeed.Feed
39-
if strings.HasPrefix("file://", *p.FeedURL) {
40-
fileData, err := ioutil.ReadFile(strings.TrimPrefix("file://", *p.FeedURL))
42+
if strings.HasPrefix(*p.FeedURL, "file://") {
43+
fileData, err := ioutil.ReadFile(strings.TrimPrefix(*p.FeedURL, "file://"))
4144
if err != nil {
4245
return err
4346
}

pkg/routes/routes.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ func RegisterRoutes(r *echo.Echo, fs stuffbin.FileSystem) {
1515
r.GET("/*", echo.WrapHandler(fs.FileServer()))
1616

1717
api := r.Group("/api/v1")
18-
{
19-
api.POST("/podcasts", handlers.PodcastsCreate)
20-
api.POST("/podcasts/import", handlers.PodcastsImport)
21-
api.GET("/podcasts", handlers.PodcastsList)
22-
api.GET("/podcasts/:id", handlers.PodcastsGet)
23-
api.GET("/podcasts/:id/episodes", handlers.PodcastsGetEpisodes)
24-
api.GET("/podcasts/:id/image", handlers.PodcastsImageGet)
25-
}
18+
api.POST("/podcasts", handlers.PodcastsCreate)
19+
api.POST("/podcasts/import", handlers.PodcastsImport)
20+
api.GET("/podcasts", handlers.PodcastsList)
21+
api.GET("/podcasts/:id", handlers.PodcastsGet)
22+
api.GET("/podcasts/:id/episodes", handlers.PodcastsGetEpisodes)
23+
api.GET("/podcasts/:id/image", handlers.PodcastsImageGet)
2624
}
2725

2826
func handleIndexPage(c echo.Context) error {

0 commit comments

Comments
 (0)