mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-16 12:01:00 +01:00
minor critics corrected
This commit is contained in:
1
Makefile
1
Makefile
@@ -63,6 +63,7 @@ lint:
|
|||||||
|
|
||||||
lint-full:
|
lint-full:
|
||||||
golangci-lint run --enable-all --exclude-use-default --disable exhaustivestruct,exhaustruct,depguard,interfacer,deadcode,golint,structcheck,scopelint,varcheck,ifshort,maligned,nosnakecase,godot,funlen,gofumpt,cyclop,noctx,gochecknoglobals,paralleltest
|
golangci-lint run --enable-all --exclude-use-default --disable exhaustivestruct,exhaustruct,depguard,interfacer,deadcode,golint,structcheck,scopelint,varcheck,ifshort,maligned,nosnakecase,godot,funlen,gofumpt,cyclop,noctx,gochecknoglobals,paralleltest
|
||||||
|
gocritic check -enableAll *.go
|
||||||
|
|
||||||
testfuzzy: clean
|
testfuzzy: clean
|
||||||
go test -fuzz ./... $(ARGS)
|
go test -fuzz ./... $(ARGS)
|
||||||
|
|||||||
2
ad.go
2
ad.go
@@ -73,7 +73,7 @@ func (ad *Ad) Incomplete() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *Ad) CalculateExpire() {
|
func (ad *Ad) CalculateExpire() {
|
||||||
if len(ad.Created) > 0 {
|
if ad.Created != "" {
|
||||||
ts, err := time.Parse("02.01.2006", ad.Created)
|
ts, err := time.Parse("02.01.2006", ad.Created)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ad.Expire = ts.AddDate(0, ExpireMonths, ExpireDays).Format("02.01.2006")
|
ad.Expire = ts.AddDate(0, ExpireMonths, ExpireDays).Format("02.01.2006")
|
||||||
|
|||||||
2
fetch.go
2
fetch.go
@@ -52,7 +52,7 @@ func NewFetcher(conf *Config) (*Fetcher, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fetcher) Get(uri string) (io.ReadCloser, error) {
|
func (f *Fetcher) Get(uri string) (io.ReadCloser, error) {
|
||||||
req, err := http.NewRequest(http.MethodGet, uri, nil)
|
req, err := http.NewRequest(http.MethodGet, uri, http.NoBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create a new HTTP request obj: %w", err)
|
return nil, fmt.Errorf("failed to create a new HTTP request obj: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
4
image.go
4
image.go
@@ -49,7 +49,7 @@ func (img *Image) LogValue() slog.Value {
|
|||||||
// holds all images of an ad
|
// holds all images of an ad
|
||||||
type Cache []*goimagehash.ImageHash
|
type Cache []*goimagehash.ImageHash
|
||||||
|
|
||||||
func NewImage(buf *bytes.Reader, filename string, uri string) *Image {
|
func NewImage(buf *bytes.Reader, filename, uri string) *Image {
|
||||||
img := &Image{
|
img := &Image{
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
URI: uri,
|
URI: uri,
|
||||||
@@ -134,7 +134,7 @@ func ReadImages(addir string, dont bool) (Cache, error) {
|
|||||||
reader := bytes.NewReader(data.Bytes())
|
reader := bytes.NewReader(data.Bytes())
|
||||||
|
|
||||||
img := NewImage(reader, filename, "")
|
img := NewImage(reader, filename, "")
|
||||||
if err = img.CalcHash(); err != nil {
|
if err := img.CalcHash(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
main_test.go
26
main_test.go
@@ -334,14 +334,14 @@ type Adsource struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render a HTML template for an adlisting or an ad
|
// Render a HTML template for an adlisting or an ad
|
||||||
func GetTemplate(adconfigs []AdConfig, adconfig AdConfig, htmltemplate string) string {
|
func GetTemplate(adconfigs []AdConfig, adconfig *AdConfig, htmltemplate string) string {
|
||||||
tmpl, err := tpl.New("template").Parse(htmltemplate)
|
tmpl, err := tpl.New("template").Parse(htmltemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
if len(adconfig.ID) == 0 {
|
if adconfig.ID == "" {
|
||||||
err = tmpl.Execute(&out, adconfigs)
|
err = tmpl.Execute(&out, adconfigs)
|
||||||
} else {
|
} else {
|
||||||
err = tmpl.Execute(&out, adconfig)
|
err = tmpl.Execute(&out, adconfig)
|
||||||
@@ -376,15 +376,15 @@ func InitValidSources() []Adsource {
|
|||||||
ads := []Adsource{
|
ads := []Adsource{
|
||||||
{
|
{
|
||||||
uri: fmt.Sprintf("%s%s?userId=1", Baseuri, Listuri),
|
uri: fmt.Sprintf("%s%s?userId=1", Baseuri, Listuri),
|
||||||
content: GetTemplate(list1, empty, LISTTPL),
|
content: GetTemplate(list1, &empty, LISTTPL),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
uri: fmt.Sprintf("%s%s?userId=1&pageNum=2", Baseuri, Listuri),
|
uri: fmt.Sprintf("%s%s?userId=1&pageNum=2", Baseuri, Listuri),
|
||||||
content: GetTemplate(list2, empty, LISTTPL),
|
content: GetTemplate(list2, &empty, LISTTPL),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
uri: fmt.Sprintf("%s%s?userId=1&pageNum=3", Baseuri, Listuri),
|
uri: fmt.Sprintf("%s%s?userId=1&pageNum=3", Baseuri, Listuri),
|
||||||
content: GetTemplate(list3, empty, LISTTPL),
|
content: GetTemplate(list3, &empty, LISTTPL),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ func InitValidSources() []Adsource {
|
|||||||
for _, ad := range adsrc {
|
for _, ad := range adsrc {
|
||||||
ads = append(ads, Adsource{
|
ads = append(ads, Adsource{
|
||||||
uri: fmt.Sprintf("%s/s-anzeige/%s/%s", Baseuri, ad.Slug, ad.ID),
|
uri: fmt.Sprintf("%s/s-anzeige/%s/%s", Baseuri, ad.Slug, ad.ID),
|
||||||
content: GetTemplate(nil, ad, ADTPL),
|
content: GetTemplate(nil, &ad, ADTPL),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,28 +405,28 @@ func InitInvalidSources() []Adsource {
|
|||||||
{
|
{
|
||||||
// valid ad page but without content
|
// valid ad page but without content
|
||||||
uri: fmt.Sprintf("%s/s-anzeige/empty/1", Baseuri),
|
uri: fmt.Sprintf("%s/s-anzeige/empty/1", Baseuri),
|
||||||
content: GetTemplate(nil, empty, EMPTYPAGE),
|
content: GetTemplate(nil, &empty, EMPTYPAGE),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// some random foreign webpage
|
// some random foreign webpage
|
||||||
uri: INVALIDURI,
|
uri: INVALIDURI,
|
||||||
content: GetTemplate(nil, empty, "<html>foo</html>"),
|
content: GetTemplate(nil, &empty, "<html>foo</html>"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// some invalid page path
|
// some invalid page path
|
||||||
uri: fmt.Sprintf("%s/anzeige/name/1", Baseuri),
|
uri: fmt.Sprintf("%s/anzeige/name/1", Baseuri),
|
||||||
content: GetTemplate(nil, empty, "<html></html>"),
|
content: GetTemplate(nil, &empty, "<html></html>"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// some none-ad page
|
// some none-ad page
|
||||||
uri: fmt.Sprintf("%s/anzeige/name/1/foo/bar", Baseuri),
|
uri: fmt.Sprintf("%s/anzeige/name/1/foo/bar", Baseuri),
|
||||||
content: GetTemplate(nil, empty, "<html>HTTP 404: /eine-anzeige/ does not exist!</html>"),
|
content: GetTemplate(nil, &empty, "<html>HTTP 404: /eine-anzeige/ does not exist!</html>"),
|
||||||
status: 404,
|
status: 404,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// valid ad page but 503
|
// valid ad page but 503
|
||||||
uri: fmt.Sprintf("%s/s-anzeige/503/1", Baseuri),
|
uri: fmt.Sprintf("%s/s-anzeige/503/1", Baseuri),
|
||||||
content: GetTemplate(nil, empty, "<html>HTTP 503: service unavailable</html>"),
|
content: GetTemplate(nil, &empty, "<html>HTTP 503: service unavailable</html>"),
|
||||||
status: 503,
|
status: 503,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ func SetIntercept(ads []Adsource) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerifyAd(advertisement AdConfig) error {
|
func VerifyAd(advertisement *AdConfig) error {
|
||||||
body := advertisement.Title + advertisement.Price + advertisement.ID + "Kleinanzeigen => " +
|
body := advertisement.Title + advertisement.Price + advertisement.ID + "Kleinanzeigen => " +
|
||||||
advertisement.Category + advertisement.Condition + advertisement.Created
|
advertisement.Category + advertisement.Condition + advertisement.Created
|
||||||
|
|
||||||
@@ -525,7 +525,7 @@ func TestMain(t *testing.T) {
|
|||||||
|
|
||||||
// verify if downloaded ads match
|
// verify if downloaded ads match
|
||||||
for _, ad := range adsrc {
|
for _, ad := range adsrc {
|
||||||
if err := VerifyAd(ad); err != nil {
|
if err := VerifyAd(&ad); err != nil {
|
||||||
t.Errorf(err.Error())
|
t.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user