Replace prazdnikisegodnyaru with celebratoday, small underhood fixes
- Replace prazdnikisegodnyaru with celebratoday as first is banned in Russia - Update .golangci.yml rule set - Megatons of fixes for linter - Update README.md
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package monkeyuser implements client for service www.monkeyusers.com.
|
||||
package monkeyuser
|
||||
|
||||
import (
|
||||
@@ -14,11 +15,13 @@ import (
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
// MonkeyUsers описывает структуру json-массива ответа www.monkeyusers.com.
|
||||
type MonkeyUsers []struct {
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
type (
|
||||
// MonkeyUsers описывает структуру json-массива ответа www.monkeyusers.com.
|
||||
MonkeyUsers []struct {
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
)
|
||||
|
||||
// APIClient клиент сервиса monkeyuser.com.
|
||||
func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
@@ -75,7 +78,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
return "", fmt.Errorf("unable to GET %s: %w", pageURL, err)
|
||||
}
|
||||
|
||||
// Парсим body ответа от сервера
|
||||
// Парсим body ответа от сервера.
|
||||
doc, err := html.Parse(strings.NewReader(body))
|
||||
|
||||
if err != nil {
|
||||
@@ -91,7 +94,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
if n.Type == html.ElementNode && n.Data == "img" {
|
||||
for _, a_href := range n.Attr { //nolint: revive
|
||||
// Если у нас class == "lazyload small-image", то после него ключ data-src должен содержать
|
||||
// искомый relative url
|
||||
// искомый relative url.
|
||||
if a_href.Key == "class" && a_href.Val == "logo" {
|
||||
continue
|
||||
}
|
||||
@@ -105,7 +108,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// traverses the HTML of the webpage from the first child node
|
||||
// traverses the HTML of the webpage from the first child node.
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
link(c)
|
||||
}
|
||||
@@ -113,7 +116,7 @@ func APIClient(cfg *config.MyConfig) (string, error) {
|
||||
|
||||
link(doc)
|
||||
|
||||
// Возвращаем ссылку на картинку buni comic
|
||||
// Возвращаем ссылку на картинку buni comic.
|
||||
if hyperlink != "" {
|
||||
return fmt.Sprintf("%s%s", baseURL, hyperlink), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user