Skip to content

Instantly share code, notes, and snippets.

@computerex
Created February 5, 2019 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computerex/75f8b760df50914add3693c431ce367f to your computer and use it in GitHub Desktop.
Save computerex/75f8b760df50914add3693c431ce367f to your computer and use it in GitHub Desktop.
fetches list of go packages
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
)
func main() {
resp, err := http.Get("https://tip.golang.org/pkg/")
if err != nil {
fmt.Println(err)
} else {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fileStr := string(body)
fmt.Println(fileStr)
r := regexp.MustCompile("(<td class=\"pkg-name\" style=\"padding-left:.*)\\W+(<a href=)\"(.*)\">(.*)(</a>)")
matches := r.FindAllStringSubmatch(fileStr, -1)
for inx := range matches {
res := matches[inx]
pkg_link := res[3]
pkg_name := res[4]
fmt.Println(pkg_name, ": ", pkg_link)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment