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 .
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="felipevm97@gmail.com"
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
|
||||
3
Makefile
3
Makefile
@@ -2,5 +2,8 @@
|
||||
build:
|
||||
docker build -t torrent-indexer .
|
||||
|
||||
lint:
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v --timeout 5m
|
||||
|
||||
run:
|
||||
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)
|
||||
if err != nil {
|
||||
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()
|
||||
return
|
||||
}
|
||||
@@ -56,7 +59,11 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
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()
|
||||
return
|
||||
}
|
||||
@@ -111,10 +118,13 @@ func (i *Indexer) HandlerBluDVIndexer(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(Response{
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: indexedTorrents,
|
||||
Count: len(indexedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getTorrentsBluDV(ctx context.Context, i *Indexer, link string) ([]IndexedTorrent, error) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@@ -63,7 +63,10 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
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()
|
||||
return
|
||||
}
|
||||
@@ -72,7 +75,10 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
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()
|
||||
return
|
||||
}
|
||||
@@ -127,10 +133,13 @@ func (i *Indexer) HandlerComandoIndexer(w http.ResponseWriter, r *http.Request)
|
||||
})
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(Response{
|
||||
err = json.NewEncoder(w).Encode(Response{
|
||||
Results: indexedTorrents,
|
||||
Count: len(indexedTorrents),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if err == nil {
|
||||
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()
|
||||
|
||||
@@ -406,7 +415,7 @@ func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Documen
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -417,7 +426,7 @@ func getDocument(ctx context.Context, i *Indexer, link string) (*goquery.Documen
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(ioutil.NopCloser(bytes.NewReader(body)))
|
||||
doc, err := goquery.NewDocumentFromReader(io.NopCloser(bytes.NewReader(body)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
||||
currentTime := time.Now().Format(time.RFC850)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
err := json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"time": currentTime,
|
||||
"endpoints": 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++ {
|
||||
select {
|
||||
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
|
||||
case err := <-errChan:
|
||||
fmt.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user