diff --git a/.codecov.yaml b/.codecov.yaml new file mode 100644 index 0000000..cae64fa --- /dev/null +++ b/.codecov.yaml @@ -0,0 +1,13 @@ +coverage: + precision: 2 + round: nearest + range: "75...100" + status: + project: + default: + target: "75%" + threshold: "0%" + patch: false + changes: false +comment: + layout: "diff, files" \ No newline at end of file diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml new file mode 100644 index 0000000..8bdcd4c --- /dev/null +++ b/.github/workflows/quality.yaml @@ -0,0 +1,49 @@ +name: quality +on: + push: + branches: + - main + pull_request: +permissions: + contents: read +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54.2 + build: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Build + run: make build + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Run tests + run: make test + - name: Upload coverage + uses: codecov/codecov-action@v3 + with: + files: coverage.out + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yaml similarity index 72% rename from .github/workflows/sync.yml rename to .github/workflows/sync.yaml index 17a0c57..ac58574 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yaml @@ -6,7 +6,6 @@ on: schedule: - cron: "0 */3 * * *" workflow_dispatch: - env: IMDB_COOKIE_AT_MAIN: ${{ secrets.IMDB_COOKIE_AT_MAIN }} IMDB_COOKIE_UBID_MAIN: ${{ secrets.IMDB_COOKIE_UBID_MAIN }} @@ -17,15 +16,17 @@ env: TRAKT_CLIENT_SECRET: ${{ secrets.TRAKT_CLIENT_SECRET }} TRAKT_EMAIL: ${{ secrets.TRAKT_EMAIL }} TRAKT_PASSWORD: ${{ secrets.TRAKT_PASSWORD }} - jobs: sync: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - name: Check out code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 with: - go-version: '1.18' - cache: true - - name: Sync watchlist, lists and ratings - run: go run cmd/syncer/main.go + go-version: 1.21 + - name: Build + run: make build + - name: Sync + run: ./build/syncer diff --git a/.gitignore b/.gitignore index ce69720..5f1e1ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,2 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ - -# Environment variables -.env - -# GoLand IDE configs -.idea/ - -# personal to do list for development purposes -TODO.md +build/ +coverage.out diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..68e2cbe --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,21 @@ +linters: + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - goimports + - misspell + - revive + - unconvert + - gci +run: + timeout: 5m +linters-settings: + revive: + rules: + - name: var-naming + arguments: + - ["ID", "URL", "HTTP", "JSON", "API"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0ad1f9e --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +.PHONY: * + +build: + go build -o build/syncer cmd/syncer/main.go + +fmt: + go fmt ./... + +html-coverage: + go tool cover -html=coverage.out + +lint: + golangci-lint run + +lint-fix: + golangci-lint run --fix + +mocks: + mockery + +test: + go test -coverpkg=./... -race -coverprofile=coverage.out -shuffle on ./... diff --git a/README.md b/README.md index f0d01c5..87df8bc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -[![sync](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/sync.yml/badge.svg?event=schedule)](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/sync.yml) +[![sync](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/sync.yml/badge.svg?event=schedule)](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/sync.yml) +[![quality](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/quality.yaml/badge.svg)](https://github.com/cecobask/imdb-trakt-sync/actions/workflows/quality.yaml) +[![codecov](https://codecov.io/gh/cecobask/imdb-trakt-sync/graph/badge.svg)](https://codecov.io/gh/cecobask/imdb-trakt-sync) # imdb-trakt-sync GoLang app that can sync [IMDb](https://www.imdb.com/) and [Trakt](https://trakt.tv/dashboard) user data - watchlist, lists, ratings and history. diff --git a/go.mod b/go.mod index c5dc04e..d9ba51a 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,15 @@ module github.com/cecobask/imdb-trakt-sync -go 1.18 +go 1.21 require ( - github.com/PuerkitoBio/goquery v1.8.0 - github.com/joho/godotenv v1.4.0 - go.uber.org/zap v1.24.0 + github.com/PuerkitoBio/goquery v1.8.1 + github.com/joho/godotenv v1.5.1 + go.uber.org/zap v1.26.0 ) require ( github.com/andybalholm/cascadia v1.3.1 // indirect - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.6.0 // indirect - golang.org/x/net v0.7.0 // indirect + go.uber.org/multierr v1.10.0 // indirect + golang.org/x/net v0.17.0 // indirect ) diff --git a/go.sum b/go.sum index fe11c5f..cc12408 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,52 @@ -github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U= -github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI= +github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM= +github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ= github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/client/client.go b/pkg/client/client.go index 64b2fd5..20241dd 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -3,9 +3,10 @@ package client import ( "bytes" "fmt" + "io" + "github.com/PuerkitoBio/goquery" "github.com/cecobask/imdb-trakt-sync/pkg/entities" - "io" ) type ImdbClientInterface interface { @@ -64,7 +65,7 @@ type reusableReader struct { func ReusableReader(r io.Reader) io.Reader { readBuf := bytes.Buffer{} - readBuf.ReadFrom(r) + _, _ = readBuf.ReadFrom(r) backBuf := bytes.Buffer{} return reusableReader{ Reader: io.TeeReader(&readBuf, &backBuf), @@ -76,7 +77,7 @@ func ReusableReader(r io.Reader) io.Reader { func (r reusableReader) Read(p []byte) (int, error) { n, err := r.Reader.Read(p) if err == io.EOF { - io.Copy(r.readBuf, r.backBuf) + _, _ = io.Copy(r.readBuf, r.backBuf) } return n, err } diff --git a/pkg/client/imdb.go b/pkg/client/imdb.go index 9d57dcc..5ffbb37 100644 --- a/pkg/client/imdb.go +++ b/pkg/client/imdb.go @@ -4,9 +4,6 @@ import ( "encoding/csv" "errors" "fmt" - "github.com/PuerkitoBio/goquery" - "github.com/cecobask/imdb-trakt-sync/pkg/entities" - "go.uber.org/zap" "mime" "net/http" "net/http/cookiejar" @@ -16,6 +13,10 @@ import ( "strings" "sync" "time" + + "github.com/PuerkitoBio/goquery" + "github.com/cecobask/imdb-trakt-sync/pkg/entities" + "go.uber.org/zap" ) const ( diff --git a/pkg/client/trakt.go b/pkg/client/trakt.go index 3664483..a389044 100644 --- a/pkg/client/trakt.go +++ b/pkg/client/trakt.go @@ -5,8 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/cecobask/imdb-trakt-sync/pkg/entities" - "go.uber.org/zap" "io" "net/http" "net/http/cookiejar" @@ -15,6 +13,9 @@ import ( "strings" "sync" "time" + + "github.com/cecobask/imdb-trakt-sync/pkg/entities" + "go.uber.org/zap" ) const ( diff --git a/pkg/entities/trakt.go b/pkg/entities/trakt.go index a1916e6..6a499fb 100644 --- a/pkg/entities/trakt.go +++ b/pkg/entities/trakt.go @@ -2,6 +2,7 @@ package entities import ( "fmt" + "go.uber.org/zap/zapcore" ) diff --git a/pkg/logger/zap.go b/pkg/logger/zap.go index d79f344..7d08b7b 100644 --- a/pkg/logger/zap.go +++ b/pkg/logger/zap.go @@ -1,10 +1,11 @@ package logger import ( - "go.uber.org/zap" - "go.uber.org/zap/zapcore" "os" "time" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) func NewLogger() *zap.Logger { diff --git a/pkg/syncer/syncer.go b/pkg/syncer/syncer.go index d3baab8..f274114 100644 --- a/pkg/syncer/syncer.go +++ b/pkg/syncer/syncer.go @@ -2,14 +2,15 @@ package syncer import ( "fmt" + "os" + "strconv" + "strings" + "github.com/cecobask/imdb-trakt-sync/pkg/client" "github.com/cecobask/imdb-trakt-sync/pkg/entities" "github.com/cecobask/imdb-trakt-sync/pkg/logger" _ "github.com/joho/godotenv/autoload" "go.uber.org/zap" - "os" - "strconv" - "strings" ) const ( diff --git a/vendor/github.com/PuerkitoBio/goquery/.gitattributes b/vendor/github.com/PuerkitoBio/goquery/.gitattributes deleted file mode 100644 index 0cc26ec..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -testdata/* linguist-vendored diff --git a/vendor/github.com/PuerkitoBio/goquery/.gitignore b/vendor/github.com/PuerkitoBio/goquery/.gitignore deleted file mode 100644 index 970381c..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# editor temporary files -*.sublime-* -.DS_Store -*.swp -#*.*# -tags - -# direnv config -.env* - -# test binaries -*.test - -# coverage and profilte outputs -*.out - diff --git a/vendor/github.com/PuerkitoBio/goquery/LICENSE b/vendor/github.com/PuerkitoBio/goquery/LICENSE deleted file mode 100644 index 25372c2..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ -Copyright (c) 2012-2021, Martin Angers & Contributors -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/PuerkitoBio/goquery/README.md b/vendor/github.com/PuerkitoBio/goquery/README.md deleted file mode 100644 index 7752234..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/README.md +++ /dev/null @@ -1,195 +0,0 @@ -# goquery - a little like that j-thing, only in Go - -[![Build Status](https://github.com/PuerkitoBio/goquery/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/PuerkitoBio/goquery/actions) -[![Go Reference](https://pkg.go.dev/badge/github.com/PuerkitoBio/goquery.svg)](https://pkg.go.dev/github.com/PuerkitoBio/goquery) -[![Sourcegraph Badge](https://sourcegraph.com/github.com/PuerkitoBio/goquery/-/badge.svg)](https://sourcegraph.com/github.com/PuerkitoBio/goquery?badge) - -goquery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on Go's [net/html package][html] and the CSS Selector library [cascadia][]. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off. - -Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. See the [wiki][] for various options to do this. - -Syntax-wise, it is as close as possible to jQuery, with the same function names when possible, and that warm and fuzzy chainable interface. jQuery being the ultra-popular library that it is, I felt that writing a similar HTML-manipulating library was better to follow its API than to start anew (in the same spirit as Go's `fmt` package), even though some of its methods are less than intuitive (looking at you, [index()][index]...). - -## Table of Contents - -* [Installation](#installation) -* [Changelog](#changelog) -* [API](#api) -* [Examples](#examples) -* [Related Projects](#related-projects) -* [Support](#support) -* [License](#license) - -## Installation - -Please note that because of the net/html dependency, goquery requires Go1.1+ and is tested on Go1.7+. - - $ go get github.com/PuerkitoBio/goquery - -(optional) To run unit tests: - - $ cd $GOPATH/src/github.com/PuerkitoBio/goquery - $ go test - -(optional) To run benchmarks (warning: it runs for a few minutes): - - $ cd $GOPATH/src/github.com/PuerkitoBio/goquery - $ go test -bench=".*" - -## Changelog - -**Note that goquery's API is now stable, and will not break.** - -* **2021-10-25 (v1.8.0)** : Add `Render` function to render a `Selection` to an `io.Writer` (thanks [@anthonygedeon](https://github.com/anthonygedeon)). -* **2021-07-11 (v1.7.1)** : Update go.mod dependencies and add dependabot config (thanks [@jauderho](https://github.com/jauderho)). -* **2021-06-14 (v1.7.0)** : Add `Single` and `SingleMatcher` functions to optimize first-match selection (thanks [@gdollardollar](https://github.com/gdollardollar)). -* **2021-01-11 (v1.6.1)** : Fix panic when calling `{Prepend,Append,Set}Html` on a `Selection` that contains non-Element nodes. -* **2020-10-08 (v1.6.0)** : Parse html in context of the container node for all functions that deal with html strings (`AfterHtml`, `AppendHtml`, etc.). Thanks to [@thiemok][thiemok] and [@davidjwilkins][djw] for their work on this. -* **2020-02-04 (v1.5.1)** : Update module dependencies. -* **2018-11-15 (v1.5.0)** : Go module support (thanks @Zaba505). -* **2018-06-07 (v1.4.1)** : Add `NewDocumentFromReader` examples. -* **2018-03-24 (v1.4.0)** : Deprecate `NewDocument(url)` and `NewDocumentFromResponse(response)`. -* **2018-01-28 (v1.3.0)** : Add `ToEnd` constant to `Slice` until the end of the selection (thanks to @davidjwilkins for raising the issue). -* **2018-01-11 (v1.2.0)** : Add `AddBack*` and deprecate `AndSelf` (thanks to @davidjwilkins). -* **2017-02-12 (v1.1.0)** : Add `SetHtml` and `SetText` (thanks to @glebtv). -* **2016-12-29 (v1.0.2)** : Optimize allocations for `Selection.Text` (thanks to @radovskyb). -* **2016-08-28 (v1.0.1)** : Optimize performance for large documents. -* **2016-07-27 (v1.0.0)** : Tag version 1.0.0. -* **2016-06-15** : Invalid selector strings internally compile to a `Matcher` implementation that never matches any node (instead of a panic). So for example, `doc.Find("~")` returns an empty `*Selection` object. -* **2016-02-02** : Add `NodeName` utility function similar to the DOM's `nodeName` property. It returns the tag name of the first element in a selection, and other relevant values of non-element nodes (see [doc][] for details). Add `OuterHtml` utility function similar to the DOM's `outerHTML` property (named `OuterHtml` in small caps for consistency with the existing `Html` method on the `Selection`). -* **2015-04-20** : Add `AttrOr` helper method to return the attribute's value or a default value if absent. Thanks to [piotrkowalczuk][piotr]. -* **2015-02-04** : Add more manipulation functions - Prepend* - thanks again to [Andrew Stone][thatguystone]. -* **2014-11-28** : Add more manipulation functions - ReplaceWith*, Wrap* and Unwrap - thanks again to [Andrew Stone][thatguystone]. -* **2014-11-07** : Add manipulation functions (thanks to [Andrew Stone][thatguystone]) and `*Matcher` functions, that receive compiled cascadia selectors instead of selector strings, thus avoiding potential panics thrown by goquery via `cascadia.MustCompile` calls. This results in better performance (selectors can be compiled once and reused) and more idiomatic error handling (you can handle cascadia's compilation errors, instead of recovering from panics, which had been bugging me for a long time). Note that the actual type expected is a `Matcher` interface, that `cascadia.Selector` implements. Other matcher implementations could be used. -* **2014-11-06** : Change import paths of net/html to golang.org/x/net/html (see https://groups.google.com/forum/#!topic/golang-nuts/eD8dh3T9yyA). Make sure to update your code to use the new import path too when you call goquery with `html.Node`s. -* **v0.3.2** : Add `NewDocumentFromReader()` (thanks jweir) which allows creating a goquery document from an io.Reader. -* **v0.3.1** : Add `NewDocumentFromResponse()` (thanks assassingj) which allows creating a goquery document from an http response. -* **v0.3.0** : Add `EachWithBreak()` which allows to break out of an `Each()` loop by returning false. This function was added instead of changing the existing `Each()` to avoid breaking compatibility. -* **v0.2.1** : Make go-getable, now that [go.net/html is Go1.0-compatible][gonet] (thanks to @matrixik for pointing this out). -* **v0.2.0** : Add support for negative indices in Slice(). **BREAKING CHANGE** `Document.Root` is removed, `Document` is now a `Selection` itself (a selection of one, the root element, just like `Document.Root` was before). Add jQuery's Closest() method. -* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases). -* **v0.1.0** : Initial release. - -## API - -goquery exposes two structs, `Document` and `Selection`, and the `Matcher` interface. Unlike jQuery, which is loaded as part of a DOM document, and thus acts on its containing document, goquery doesn't know which HTML document to act upon. So it needs to be told, and that's what the `Document` type is for. It holds the root document node as the initial Selection value to manipulate. - -jQuery often has many variants for the same function (no argument, a selector string argument, a jQuery object argument, a DOM element argument, ...). Instead of exposing the same features in goquery as a single method with variadic empty interface arguments, statically-typed signatures are used following this naming convention: - -* When the jQuery equivalent can be called with no argument, it has the same name as jQuery for the no argument signature (e.g.: `Prev()`), and the version with a selector string argument is called `XxxFiltered()` (e.g.: `PrevFiltered()`) -* When the jQuery equivalent **requires** one argument, the same name as jQuery is used for the selector string version (e.g.: `Is()`) -* The signatures accepting a jQuery object as argument are defined in goquery as `XxxSelection()` and take a `*Selection` object as argument (e.g.: `FilterSelection()`) -* The signatures accepting a DOM element as argument in jQuery are defined in goquery as `XxxNodes()` and take a variadic argument of type `*html.Node` (e.g.: `FilterNodes()`) -* The signatures accepting a function as argument in jQuery are defined in goquery as `XxxFunction()` and take a function as argument (e.g.: `FilterFunction()`) -* The goquery methods that can be called with a selector string have a corresponding version that take a `Matcher` interface and are defined as `XxxMatcher()` (e.g.: `IsMatcher()`) - -Utility functions that are not in jQuery but are useful in Go are implemented as functions (that take a `*Selection` as parameter), to avoid a potential naming clash on the `*Selection`'s methods (reserved for jQuery-equivalent behaviour). - -The complete [package reference documentation can be found here][doc]. - -Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string): - -* `Find("~")` returns an empty selection because the selector string doesn't match anything. -* `Add("~")` returns a new selection that holds the same nodes as the original selection, because it didn't add any node (selector string didn't match anything). -* `ParentsFiltered("~")` returns an empty selection because the selector string doesn't match anything. -* `ParentsUntil("~")` returns all parents of the selection because the selector string didn't match any element to stop before the top element. - -## Examples - -See some tips and tricks in the [wiki][]. - -Adapted from example_test.go: - -```Go -package main - -import ( - "fmt" - "log" - "net/http" - - "github.com/PuerkitoBio/goquery" -) - -func ExampleScrape() { - // Request the HTML page. - res, err := http.Get("http://metalsucks.net") - if err != nil { - log.Fatal(err) - } - defer res.Body.Close() - if res.StatusCode != 200 { - log.Fatalf("status code error: %d %s", res.StatusCode, res.Status) - } - - // Load the HTML document - doc, err := goquery.NewDocumentFromReader(res.Body) - if err != nil { - log.Fatal(err) - } - - // Find the review items - doc.Find(".left-content article .post-title").Each(func(i int, s *goquery.Selection) { - // For each item found, get the title - title := s.Find("a").Text() - fmt.Printf("Review %d: %s\n", i, title) - }) -} - -func main() { - ExampleScrape() -} -``` - -## Related Projects - -- [Goq][goq], an HTML deserialization and scraping library based on goquery and struct tags. -- [andybalholm/cascadia][cascadia], the CSS selector library used by goquery. -- [suntong/cascadia][cascadiacli], a command-line interface to the cascadia CSS selector library, useful to test selectors. -- [gocolly/colly](https://github.com/gocolly/colly), a lightning fast and elegant Scraping Framework -- [gnulnx/goperf](https://github.com/gnulnx/goperf), a website performance test tool that also fetches static assets. -- [MontFerret/ferret](https://github.com/MontFerret/ferret), declarative web scraping. -- [tacusci/berrycms](https://github.com/tacusci/berrycms), a modern simple to use CMS with easy to write plugins -- [Dataflow kit](https://github.com/slotix/dataflowkit), Web Scraping framework for Gophers. -- [Geziyor](https://github.com/geziyor/geziyor), a fast web crawling & scraping framework for Go. Supports JS rendering. -- [Pagser](https://github.com/foolin/pagser), a simple, easy, extensible, configurable HTML parser to struct based on goquery and struct tags. -- [stitcherd](https://github.com/vhodges/stitcherd), A server for doing server side includes using css selectors and DOM updates. - -## Support - -There are a number of ways you can support the project: - -* Use it, star it, build something with it, spread the word! - - If you do build something open-source or otherwise publicly-visible, let me know so I can add it to the [Related Projects](#related-projects) section! -* Raise issues to improve the project (note: doc typos and clarifications are issues too!) - - Please search existing issues before opening a new one - it may have already been adressed. -* Pull requests: please discuss new code in an issue first, unless the fix is really trivial. - - Make sure new code is tested. - - Be mindful of existing code - PRs that break existing code have a high probability of being declined, unless it fixes a serious issue. -* Sponsor the developer - - See the Github Sponsor button at the top of the repo on github - - or via BuyMeACoffee.com, below - - - -## License - -The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic]. - -[jquery]: http://jquery.com/ -[go]: http://golang.org/ -[cascadia]: https://github.com/andybalholm/cascadia -[cascadiacli]: https://github.com/suntong/cascadia -[bsd]: http://opensource.org/licenses/BSD-3-Clause -[golic]: http://golang.org/LICENSE -[caslic]: https://github.com/andybalholm/cascadia/blob/master/LICENSE -[doc]: https://pkg.go.dev/github.com/PuerkitoBio/goquery -[index]: http://api.jquery.com/index/ -[gonet]: https://github.com/golang/net/ -[html]: https://pkg.go.dev/golang.org/x/net/html -[wiki]: https://github.com/PuerkitoBio/goquery/wiki/Tips-and-tricks -[thatguystone]: https://github.com/thatguystone -[piotr]: https://github.com/piotrkowalczuk -[goq]: https://github.com/andrewstuart/goq -[thiemok]: https://github.com/thiemok -[djw]: https://github.com/davidjwilkins diff --git a/vendor/github.com/PuerkitoBio/goquery/array.go b/vendor/github.com/PuerkitoBio/goquery/array.go deleted file mode 100644 index 1b1f6cb..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/array.go +++ /dev/null @@ -1,124 +0,0 @@ -package goquery - -import ( - "golang.org/x/net/html" -) - -const ( - maxUint = ^uint(0) - maxInt = int(maxUint >> 1) - - // ToEnd is a special index value that can be used as end index in a call - // to Slice so that all elements are selected until the end of the Selection. - // It is equivalent to passing (*Selection).Length(). - ToEnd = maxInt -) - -// First reduces the set of matched elements to the first in the set. -// It returns a new Selection object, and an empty Selection object if the -// the selection is empty. -func (s *Selection) First() *Selection { - return s.Eq(0) -} - -// Last reduces the set of matched elements to the last in the set. -// It returns a new Selection object, and an empty Selection object if -// the selection is empty. -func (s *Selection) Last() *Selection { - return s.Eq(-1) -} - -// Eq reduces the set of matched elements to the one at the specified index. -// If a negative index is given, it counts backwards starting at the end of the -// set. It returns a new Selection object, and an empty Selection object if the -// index is invalid. -func (s *Selection) Eq(index int) *Selection { - if index < 0 { - index += len(s.Nodes) - } - - if index >= len(s.Nodes) || index < 0 { - return newEmptySelection(s.document) - } - - return s.Slice(index, index+1) -} - -// Slice reduces the set of matched elements to a subset specified by a range -// of indices. The start index is 0-based and indicates the index of the first -// element to select. The end index is 0-based and indicates the index at which -// the elements stop being selected (the end index is not selected). -// -// The indices may be negative, in which case they represent an offset from the -// end of the selection. -// -// The special value ToEnd may be specified as end index, in which case all elements -// until the end are selected. This works both for a positive and negative start -// index. -func (s *Selection) Slice(start, end int) *Selection { - if start < 0 { - start += len(s.Nodes) - } - if end == ToEnd { - end = len(s.Nodes) - } else if end < 0 { - end += len(s.Nodes) - } - return pushStack(s, s.Nodes[start:end]) -} - -// Get retrieves the underlying node at the specified index. -// Get without parameter is not implemented, since the node array is available -// on the Selection object. -func (s *Selection) Get(index int) *html.Node { - if index < 0 { - index += len(s.Nodes) // Negative index gets from the end - } - return s.Nodes[index] -} - -// Index returns the position of the first element within the Selection object -// relative to its sibling elements. -func (s *Selection) Index() int { - if len(s.Nodes) > 0 { - return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length() - } - return -1 -} - -// IndexSelector returns the position of the first element within the -// Selection object relative to the elements matched by the selector, or -1 if -// not found. -func (s *Selection) IndexSelector(selector string) int { - if len(s.Nodes) > 0 { - sel := s.document.Find(selector) - return indexInSlice(sel.Nodes, s.Nodes[0]) - } - return -1 -} - -// IndexMatcher returns the position of the first element within the -// Selection object relative to the elements matched by the matcher, or -1 if -// not found. -func (s *Selection) IndexMatcher(m Matcher) int { - if len(s.Nodes) > 0 { - sel := s.document.FindMatcher(m) - return indexInSlice(sel.Nodes, s.Nodes[0]) - } - return -1 -} - -// IndexOfNode returns the position of the specified node within the Selection -// object, or -1 if not found. -func (s *Selection) IndexOfNode(node *html.Node) int { - return indexInSlice(s.Nodes, node) -} - -// IndexOfSelection returns the position of the first node in the specified -// Selection object within this Selection object, or -1 if not found. -func (s *Selection) IndexOfSelection(sel *Selection) int { - if sel != nil && len(sel.Nodes) > 0 { - return indexInSlice(s.Nodes, sel.Nodes[0]) - } - return -1 -} diff --git a/vendor/github.com/PuerkitoBio/goquery/doc.go b/vendor/github.com/PuerkitoBio/goquery/doc.go deleted file mode 100644 index 71146a7..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/doc.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2012-2016, Martin Angers & Contributors -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation and/or -// other materials provided with the distribution. -// * Neither the name of the author nor the names of its contributors may be used to -// endorse or promote products derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS -// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY -// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* -Package goquery implements features similar to jQuery, including the chainable -syntax, to manipulate and query an HTML document. - -It brings a syntax and a set of features similar to jQuery to the Go language. -It is based on Go's net/html package and the CSS Selector library cascadia. -Since the net/html parser returns nodes, and not a full-featured DOM -tree, jQuery's stateful manipulation functions (like height(), css(), detach()) -have been left off. - -Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is -the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. -See the repository's wiki for various options on how to do this. - -Syntax-wise, it is as close as possible to jQuery, with the same method names when -possible, and that warm and fuzzy chainable interface. jQuery being the -ultra-popular library that it is, writing a similar HTML-manipulating -library was better to follow its API than to start anew (in the same spirit as -Go's fmt package), even though some of its methods are less than intuitive (looking -at you, index()...). - -It is hosted on GitHub, along with additional documentation in the README.md -file: https://github.com/puerkitobio/goquery - -Please note that because of the net/html dependency, goquery requires Go1.1+. - -The various methods are split into files based on the category of behavior. -The three dots (...) indicate that various "overloads" are available. - -* array.go : array-like positional manipulation of the selection. - - Eq() - - First() - - Get() - - Index...() - - Last() - - Slice() - -* expand.go : methods that expand or augment the selection's set. - - Add...() - - AndSelf() - - Union(), which is an alias for AddSelection() - -* filter.go : filtering methods, that reduce the selection's set. - - End() - - Filter...() - - Has...() - - Intersection(), which is an alias of FilterSelection() - - Not...() - -* iteration.go : methods to loop over the selection's nodes. - - Each() - - EachWithBreak() - - Map() - -* manipulation.go : methods for modifying the document - - After...() - - Append...() - - Before...() - - Clone() - - Empty() - - Prepend...() - - Remove...() - - ReplaceWith...() - - Unwrap() - - Wrap...() - - WrapAll...() - - WrapInner...() - -* property.go : methods that inspect and get the node's properties values. - - Attr*(), RemoveAttr(), SetAttr() - - AddClass(), HasClass(), RemoveClass(), ToggleClass() - - Html() - - Length() - - Size(), which is an alias for Length() - - Text() - -* query.go : methods that query, or reflect, a node's identity. - - Contains() - - Is...() - -* traversal.go : methods to traverse the HTML document tree. - - Children...() - - Contents() - - Find...() - - Next...() - - Parent[s]...() - - Prev...() - - Siblings...() - -* type.go : definition of the types exposed by goquery. - - Document - - Selection - - Matcher - -* utilities.go : definition of helper functions (and not methods on a *Selection) -that are not part of jQuery, but are useful to goquery. - - NodeName - - OuterHtml -*/ -package goquery diff --git a/vendor/github.com/PuerkitoBio/goquery/expand.go b/vendor/github.com/PuerkitoBio/goquery/expand.go deleted file mode 100644 index 7caade5..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/expand.go +++ /dev/null @@ -1,70 +0,0 @@ -package goquery - -import "golang.org/x/net/html" - -// Add adds the selector string's matching nodes to those in the current -// selection and returns a new Selection object. -// The selector string is run in the context of the document of the current -// Selection object. -func (s *Selection) Add(selector string) *Selection { - return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...) -} - -// AddMatcher adds the matcher's matching nodes to those in the current -// selection and returns a new Selection object. -// The matcher is run in the context of the document of the current -// Selection object. -func (s *Selection) AddMatcher(m Matcher) *Selection { - return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...) -} - -// AddSelection adds the specified Selection object's nodes to those in the -// current selection and returns a new Selection object. -func (s *Selection) AddSelection(sel *Selection) *Selection { - if sel == nil { - return s.AddNodes() - } - return s.AddNodes(sel.Nodes...) -} - -// Union is an alias for AddSelection. -func (s *Selection) Union(sel *Selection) *Selection { - return s.AddSelection(sel) -} - -// AddNodes adds the specified nodes to those in the -// current selection and returns a new Selection object. -func (s *Selection) AddNodes(nodes ...*html.Node) *Selection { - return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil)) -} - -// AndSelf adds the previous set of elements on the stack to the current set. -// It returns a new Selection object containing the current Selection combined -// with the previous one. -// Deprecated: This function has been deprecated and is now an alias for AddBack(). -func (s *Selection) AndSelf() *Selection { - return s.AddBack() -} - -// AddBack adds the previous set of elements on the stack to the current set. -// It returns a new Selection object containing the current Selection combined -// with the previous one. -func (s *Selection) AddBack() *Selection { - return s.AddSelection(s.prevSel) -} - -// AddBackFiltered reduces the previous set of elements on the stack to those that -// match the selector string, and adds them to the current set. -// It returns a new Selection object containing the current Selection combined -// with the filtered previous one -func (s *Selection) AddBackFiltered(selector string) *Selection { - return s.AddSelection(s.prevSel.Filter(selector)) -} - -// AddBackMatcher reduces the previous set of elements on the stack to those that match -// the mateher, and adds them to the curernt set. -// It returns a new Selection object containing the current Selection combined -// with the filtered previous one -func (s *Selection) AddBackMatcher(m Matcher) *Selection { - return s.AddSelection(s.prevSel.FilterMatcher(m)) -} diff --git a/vendor/github.com/PuerkitoBio/goquery/filter.go b/vendor/github.com/PuerkitoBio/goquery/filter.go deleted file mode 100644 index 9138ffb..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/filter.go +++ /dev/null @@ -1,163 +0,0 @@ -package goquery - -import "golang.org/x/net/html" - -// Filter reduces the set of matched elements to those that match the selector string. -// It returns a new Selection object for this subset of matching elements. -func (s *Selection) Filter(selector string) *Selection { - return s.FilterMatcher(compileMatcher(selector)) -} - -// FilterMatcher reduces the set of matched elements to those that match -// the given matcher. It returns a new Selection object for this subset -// of matching elements. -func (s *Selection) FilterMatcher(m Matcher) *Selection { - return pushStack(s, winnow(s, m, true)) -} - -// Not removes elements from the Selection that match the selector string. -// It returns a new Selection object with the matching elements removed. -func (s *Selection) Not(selector string) *Selection { - return s.NotMatcher(compileMatcher(selector)) -} - -// NotMatcher removes elements from the Selection that match the given matcher. -// It returns a new Selection object with the matching elements removed. -func (s *Selection) NotMatcher(m Matcher) *Selection { - return pushStack(s, winnow(s, m, false)) -} - -// FilterFunction reduces the set of matched elements to those that pass the function's test. -// It returns a new Selection object for this subset of elements. -func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection { - return pushStack(s, winnowFunction(s, f, true)) -} - -// NotFunction removes elements from the Selection that pass the function's test. -// It returns a new Selection object with the matching elements removed. -func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection { - return pushStack(s, winnowFunction(s, f, false)) -} - -// FilterNodes reduces the set of matched elements to those that match the specified nodes. -// It returns a new Selection object for this subset of elements. -func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection { - return pushStack(s, winnowNodes(s, nodes, true)) -} - -// NotNodes removes elements from the Selection that match the specified nodes. -// It returns a new Selection object with the matching elements removed. -func (s *Selection) NotNodes(nodes ...*html.Node) *Selection { - return pushStack(s, winnowNodes(s, nodes, false)) -} - -// FilterSelection reduces the set of matched elements to those that match a -// node in the specified Selection object. -// It returns a new Selection object for this subset of elements. -func (s *Selection) FilterSelection(sel *Selection) *Selection { - if sel == nil { - return pushStack(s, winnowNodes(s, nil, true)) - } - return pushStack(s, winnowNodes(s, sel.Nodes, true)) -} - -// NotSelection removes elements from the Selection that match a node in the specified -// Selection object. It returns a new Selection object with the matching elements removed. -func (s *Selection) NotSelection(sel *Selection) *Selection { - if sel == nil { - return pushStack(s, winnowNodes(s, nil, false)) - } - return pushStack(s, winnowNodes(s, sel.Nodes, false)) -} - -// Intersection is an alias for FilterSelection. -func (s *Selection) Intersection(sel *Selection) *Selection { - return s.FilterSelection(sel) -} - -// Has reduces the set of matched elements to those that have a descendant -// that matches the selector. -// It returns a new Selection object with the matching elements. -func (s *Selection) Has(selector string) *Selection { - return s.HasSelection(s.document.Find(selector)) -} - -// HasMatcher reduces the set of matched elements to those that have a descendant -// that matches the matcher. -// It returns a new Selection object with the matching elements. -func (s *Selection) HasMatcher(m Matcher) *Selection { - return s.HasSelection(s.document.FindMatcher(m)) -} - -// HasNodes reduces the set of matched elements to those that have a -// descendant that matches one of the nodes. -// It returns a new Selection object with the matching elements. -func (s *Selection) HasNodes(nodes ...*html.Node) *Selection { - return s.FilterFunction(func(_ int, sel *Selection) bool { - // Add all nodes that contain one of the specified nodes - for _, n := range nodes { - if sel.Contains(n) { - return true - } - } - return false - }) -} - -// HasSelection reduces the set of matched elements to those that have a -// descendant that matches one of the nodes of the specified Selection object. -// It returns a new Selection object with the matching elements. -func (s *Selection) HasSelection(sel *Selection) *Selection { - if sel == nil { - return s.HasNodes() - } - return s.HasNodes(sel.Nodes...) -} - -// End ends the most recent filtering operation in the current chain and -// returns the set of matched elements to its previous state. -func (s *Selection) End() *Selection { - if s.prevSel != nil { - return s.prevSel - } - return newEmptySelection(s.document) -} - -// Filter based on the matcher, and the indicator to keep (Filter) or -// to get rid of (Not) the matching elements. -func winnow(sel *Selection, m Matcher, keep bool) []*html.Node { - // Optimize if keep is requested - if keep { - return m.Filter(sel.Nodes) - } - // Use grep - return grep(sel, func(i int, s *Selection) bool { - return !m.Match(s.Get(0)) - }) -} - -// Filter based on an array of nodes, and the indicator to keep (Filter) or -// to get rid of (Not) the matching elements. -func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node { - if len(nodes)+len(sel.Nodes) < minNodesForSet { - return grep(sel, func(i int, s *Selection) bool { - return isInSlice(nodes, s.Get(0)) == keep - }) - } - - set := make(map[*html.Node]bool) - for _, n := range nodes { - set[n] = true - } - return grep(sel, func(i int, s *Selection) bool { - return set[s.Get(0)] == keep - }) -} - -// Filter based on a function test, and the indicator to keep (Filter) or -// to get rid of (Not) the matching elements. -func winnowFunction(sel *Selection, f func(int, *Selection) bool, keep bool) []*html.Node { - return grep(sel, func(i int, s *Selection) bool { - return f(i, s) == keep - }) -} diff --git a/vendor/github.com/PuerkitoBio/goquery/iteration.go b/vendor/github.com/PuerkitoBio/goquery/iteration.go deleted file mode 100644 index e246f2e..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/iteration.go +++ /dev/null @@ -1,39 +0,0 @@ -package goquery - -// Each iterates over a Selection object, executing a function for each -// matched element. It returns the current Selection object. The function -// f is called for each element in the selection with the index of the -// element in that selection starting at 0, and a *Selection that contains -// only that element. -func (s *Selection) Each(f func(int, *Selection)) *Selection { - for i, n := range s.Nodes { - f(i, newSingleSelection(n, s.document)) - } - return s -} - -// EachWithBreak iterates over a Selection object, executing a function for each -// matched element. It is identical to Each except that it is possible to break -// out of the loop by returning false in the callback function. It returns the -// current Selection object. -func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { - for i, n := range s.Nodes { - if !f(i, newSingleSelection(n, s.document)) { - return s - } - } - return s -} - -// Map passes each element in the current matched set through a function, -// producing a slice of string holding the returned values. The function -// f is called for each element in the selection with the index of the -// element in that selection starting at 0, and a *Selection that contains -// only that element. -func (s *Selection) Map(f func(int, *Selection) string) (result []string) { - for i, n := range s.Nodes { - result = append(result, f(i, newSingleSelection(n, s.document))) - } - - return result -} diff --git a/vendor/github.com/PuerkitoBio/goquery/manipulation.go b/vendor/github.com/PuerkitoBio/goquery/manipulation.go deleted file mode 100644 index 35febf1..0000000 --- a/vendor/github.com/PuerkitoBio/goquery/manipulation.go +++ /dev/null @@ -1,679 +0,0 @@ -package goquery - -import ( - "strings" - - "golang.org/x/net/html" -) - -// After applies the selector from the root document and inserts the matched elements -// after the elements in the set of matched elements. -// -// If one of the matched elements in the selection is not currently in the -// document, it's impossible to insert nodes after it, so it will be ignored. -// -// This follows the same rules as Selection.Append. -func (s *Selection) After(selector string) *Selection { - return s.AfterMatcher(compileMatcher(selector)) -} - -// AfterMatcher applies the matcher from the root document and inserts the matched elements -// after the elements in the set of matched elements. -// -// If one of the matched elements in the selection is not currently in the -// document, it's impossible to insert nodes after it, so it will be ignored. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AfterMatcher(m Matcher) *Selection { - return s.AfterNodes(m.MatchAll(s.document.rootNode)...) -} - -// AfterSelection inserts the elements in the selection after each element in the set of matched -// elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AfterSelection(sel *Selection) *Selection { - return s.AfterNodes(sel.Nodes...) -} - -// AfterHtml parses the html and inserts it after the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AfterHtml(htmlStr string) *Selection { - return s.eachNodeHtml(htmlStr, true, func(node *html.Node, nodes []*html.Node) { - nextSibling := node.NextSibling - for _, n := range nodes { - if node.Parent != nil { - node.Parent.InsertBefore(n, nextSibling) - } - } - }) -} - -// AfterNodes inserts the nodes after each element in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AfterNodes(ns ...*html.Node) *Selection { - return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) { - if sn.Parent != nil { - sn.Parent.InsertBefore(n, sn.NextSibling) - } - }) -} - -// Append appends the elements specified by the selector to the end of each element -// in the set of matched elements, following those rules: -// -// 1) The selector is applied to the root document. -// -// 2) Elements that are part of the document will be moved to the new location. -// -// 3) If there are multiple locations to append to, cloned nodes will be -// appended to all target locations except the last one, which will be moved -// as noted in (2). -func (s *Selection) Append(selector string) *Selection { - return s.AppendMatcher(compileMatcher(selector)) -} - -// AppendMatcher appends the elements specified by the matcher to the end of each element -// in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AppendMatcher(m Matcher) *Selection { - return s.AppendNodes(m.MatchAll(s.document.rootNode)...) -} - -// AppendSelection appends the elements in the selection to the end of each element -// in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AppendSelection(sel *Selection) *Selection { - return s.AppendNodes(sel.Nodes...) -} - -// AppendHtml parses the html and appends it to the set of matched elements. -func (s *Selection) AppendHtml(htmlStr string) *Selection { - return s.eachNodeHtml(htmlStr, false, func(node *html.Node, nodes []*html.Node) { - for _, n := range nodes { - node.AppendChild(n) - } - }) -} - -// AppendNodes appends the specified nodes to each node in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) AppendNodes(ns ...*html.Node) *Selection { - return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) { - sn.AppendChild(n) - }) -} - -// Before inserts the matched elements before each element in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) Before(selector string) *Selection { - return s.BeforeMatcher(compileMatcher(selector)) -} - -// BeforeMatcher inserts the matched elements before each element in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) BeforeMatcher(m Matcher) *Selection { - return s.BeforeNodes(m.MatchAll(s.document.rootNode)...) -} - -// BeforeSelection inserts the elements in the selection before each element in the set of matched -// elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) BeforeSelection(sel *Selection) *Selection { - return s.BeforeNodes(sel.Nodes...) -} - -// BeforeHtml parses the html and inserts it before the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) BeforeHtml(htmlStr string) *Selection { - return s.eachNodeHtml(htmlStr, true, func(node *html.Node, nodes []*html.Node) { - for _, n := range nodes { - if node.Parent != nil { - node.Parent.InsertBefore(n, node) - } - } - }) -} - -// BeforeNodes inserts the nodes before each element in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection { - return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) { - if sn.Parent != nil { - sn.Parent.InsertBefore(n, sn) - } - }) -} - -// Clone creates a deep copy of the set of matched nodes. The new nodes will not be -// attached to the document. -func (s *Selection) Clone() *Selection { - ns := newEmptySelection(s.document) - ns.Nodes = cloneNodes(s.Nodes) - return ns -} - -// Empty removes all children nodes from the set of matched elements. -// It returns the children nodes in a new Selection. -func (s *Selection) Empty() *Selection { - var nodes []*html.Node - - for _, n := range s.Nodes { - for c := n.FirstChild; c != nil; c = n.FirstChild { - n.RemoveChild(c) - nodes = append(nodes, c) - } - } - - return pushStack(s, nodes) -} - -// Prepend prepends the elements specified by the selector to each element in -// the set of matched elements, following the same rules as Append. -func (s *Selection) Prepend(selector string) *Selection { - return s.PrependMatcher(compileMatcher(selector)) -} - -// PrependMatcher prepends the elements specified by the matcher to each -// element in the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) PrependMatcher(m Matcher) *Selection { - return s.PrependNodes(m.MatchAll(s.document.rootNode)...) -} - -// PrependSelection prepends the elements in the selection to each element in -// the set of matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) PrependSelection(sel *Selection) *Selection { - return s.PrependNodes(sel.Nodes...) -} - -// PrependHtml parses the html and prepends it to the set of matched elements. -func (s *Selection) PrependHtml(htmlStr string) *Selection { - return s.eachNodeHtml(htmlStr, false, func(node *html.Node, nodes []*html.Node) { - firstChild := node.FirstChild - for _, n := range nodes { - node.InsertBefore(n, firstChild) - } - }) -} - -// PrependNodes prepends the specified nodes to each node in the set of -// matched elements. -// -// This follows the same rules as Selection.Append. -func (s *Selection) PrependNodes(ns ...*html.Node) *Selection { - return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) { - // sn.FirstChild may be nil, in which case this functions like - // sn.AppendChild() - sn.InsertBefore(n, sn.FirstChild) - }) -} - -// Remove removes the set of matched elements from the document. -// It returns the same selection, now consisting of nodes not in the document. -func (s *Selection) Remove() *Selection { - for _, n := range s.Nodes { - if n.Parent != nil { - n.Parent.RemoveChild(n) - } - } - - return s -} - -// RemoveFiltered removes from the current set of matched elements those that -// match the selector filter. It returns the Selection of removed nodes. -// -// For example if the selection s contains "