chg: chore: add linter
This commit is contained in:
3
.golangci.yml
Normal file
3
.golangci.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
run:
|
||||||
|
skip-files:
|
||||||
|
- scrape.go
|
||||||
@@ -8,6 +8,7 @@ RUN go install -v ./...
|
|||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
LABEL maintainer="felipevm97@gmail.com"
|
||||||
|
|
||||||
RUN apk --no-cache add ca-certificates
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -2,5 +2,8 @@
|
|||||||
build:
|
build:
|
||||||
docker build -t torrent-indexer .
|
docker build -t torrent-indexer .
|
||||||
|
|
||||||
|
lint:
|
||||||
|
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v --timeout 5m
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run main.go
|
go run main.go
|
||||||
|
|||||||
16
api/bludv.go
16
api/bludv.go
@@ -47,7 +47,10 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -56,7 +59,11 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
|||||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
i.metrics.IndexerErrors.WithLabelValues("bludv").Inc()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -111,10 +118,13 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(Response{
|
err = json.NewEncoder(w).Encode(Response{
|
||||||
Results: indexedTorrents,
|
Results: indexedTorrents,
|
||||||
Count: len(indexedTorrents),
|
Count: len(indexedTorrents),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -63,7 +63,10 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
|||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,10 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
|||||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
err = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
i.metrics.IndexerErrors.WithLabelValues("comando").Inc()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -127,10 +133,13 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
|||||||
})
|
})
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(Response{
|
err = json.NewEncoder(w).Encode(Response{
|
||||||
Results: indexedTorrents,
|
Results: indexedTorrents,
|
||||||
Count: len(indexedTorrents),
|
Count: len(indexedTorrents),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTorrents(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
func getTorrents(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
||||||
@@ -396,7 +405,7 @@ func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Documen
|
|||||||
docCache, err := i.redis.Get(ctx, link)
|
docCache, err := i.redis.Get(ctx, link)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
i.metrics.CacheHits.WithLabelValues("document_body").Inc()
|
i.metrics.CacheHits.WithLabelValues("document_body").Inc()
|
||||||
return goquery.NewDocumentFromReader(ioutil.NopCloser(bytes.NewReader(docCache)))
|
return goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(docCache)))
|
||||||
}
|
}
|
||||||
defer i.metrics.CacheMisses.WithLabelValues("document_body").Inc()
|
defer i.metrics.CacheMisses.WithLabelValues("document_body").Inc()
|
||||||
|
|
||||||
@@ -406,7 +415,7 @@ func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Documen
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -417,7 +426,7 @@ func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Documen
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, err := goquery.NewDocumentFromReader(ioutil.NopCloser(bytes.NewReader(body)))
|
doc, err := goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(body)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
currentTime := time.Now().Format(time.RFC850)
|
currentTime := time.Now().Format(time.RFC850)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
err := json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
"time": currentTime,
|
"time": currentTime,
|
||||||
"endpoints": map[string]interface{}{
|
"endpoints": map[string]interface{}{
|
||||||
"/indexers/comando_torrents": map[string]interface{}{
|
"/indexers/comando_torrents": map[string]interface{}{
|
||||||
@@ -74,4 +74,7 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,10 @@ func GetLeechsAndSeeds(ctx context.Context, r *cache.Redis, m *monitoring.Metric
|
|||||||
for i := 0; i < len(trackers); i++ {
|
for i := 0; i < len(trackers); i++ {
|
||||||
select {
|
select {
|
||||||
case peer = <-peerChan:
|
case peer = <-peerChan:
|
||||||
setPeersToCache(ctx, r, infoHash, peer.Leechers, peer.Seeders)
|
err = setPeersToCache(ctx, r, infoHash, peer.Leechers, peer.Seeders)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
return peer.Leechers, peer.Seeders, nil
|
return peer.Leechers, peer.Seeders, nil
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user