Skip to content

Commit

Permalink
gopkgimps: don't use json
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Aug 1, 2024
1 parent 293a249 commit aae6671
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
7 changes: 3 additions & 4 deletions chore/gopkgimps/gopkgimps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package main

import (
"encoding/json"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -46,7 +45,7 @@ func main() {
sort.Slice(docs, func(i, j int) bool {
return docs[i].ImportedBy > docs[j].ImportedBy
})
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(docs)
for _, doc := range docs {
fmt.Println(doc.Path, doc.ImportedBy)

Check warning on line 49 in chore/gopkgimps/gopkgimps.go

View check run for this annotation

qiniu-x / golangci-lint

chore/gopkgimps/gopkgimps.go#L49

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
}
}
53 changes: 29 additions & 24 deletions fetcher/gopkg/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions fetcher/gopkg/gopkg_imps.gop
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ import (
)

type Result struct {
Name string `json:"name"`
Path string `json:"path"`
ImportedBy int `json:"importedBy"`
}

// New creates a new Result from a html document.
func New(input any, doc hdq.NodeSet) Result {
const importedByPrefix = "Imported By:"
name := input.(string)
path := input.(string)
a := doc.any.a.attribute("aria-label", v => strings.hasPrefix(v, importedByPrefix)).one
if !a.ok {
return {path, 0}
}
label := a.attr("aria-label")!
labelVal := strings.trimSpace(label[len(importedByPrefix):])
importedBy := strings.replaceAll(labelVal, ",", "").int!
return {name, importedBy}
return {path, importedBy}
}

// URL returns the input URL for the given name.
Expand Down

0 comments on commit aae6671

Please sign in to comment.