Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak go resolver #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Tweak go resolver #444

wants to merge 1 commit into from

Conversation

stefanbuck
Copy link
Member

Previously we had to do a weird dance to get the target url of a package by extracting that url from a meta-tag as explained here. This doesn't work anymore since https://k8s.io/<package> got replaced by https://pkg.go.dev/<package>. Now pkg.go.dev seems to host all standard and external packages. This allows use to use pkg.go.dev as a single source. Unfortunately they don't have a REST API golang/go#36785 so we have to scrape the data from their website.

@vercel
Copy link

vercel bot commented Apr 12, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/octolinker/octolinker-api/9hE4HcPkRq48d4miubUCZyMh9i5n
✅ Preview: https://octolinker-api-git-tweak-go-resolver-octolinker1.vercel.app

}

await cache.set(cacheKey, reachableUrl);
const [, targetUrl] = /UnitMeta-repo">[\n\s]+<a href="([^"]+)/g.exec(response.body);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a regex to scrape data off a website isn't ideal, but adding https://github.com/jsdom/jsdom doesn't help either if the classname changes. Ideally pkg.go.dev should expose a REST API, but this is not the case golang/go#36785 (yet?)

],
{ firstMatch: true },
);
const isStdLib = response.body.includes('standard library');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this check, import "context" would resolve to https://cs.opensource.google/go/go, but the actual https://pkg.go.dev/context might be more interesting in this case

@stefanbuck
Copy link
Member Author

Once this is live, we should be able to get rid off https://github.com/OctoLinker/OctoLinker/blob/343ff1e350d8c446ae3f152c747f9cf2b42331b9/packages/plugin-go/index.js#L52-L53 and use to go resolver all the time given that this page is hosting all packages

@shellscape
Copy link

Hey saw this by chance from the referenced issue. You can still get the vanity url resolver (if that's what you're after). If a package "name" starts with github.com, you're good to go. If it's anything else, you load the url with curl, and look for the go-import meta tag. Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants