Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/268'
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Apr 24, 2024
2 parents c367b49 + 62fdca8 commit 5140fa2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions nvchecker_source/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
from lxml import html

from nvchecker.api import (
VersionResult, Entry, AsyncCache, KeyManager,
RichResult, Entry, AsyncCache, KeyManager,
session, GetVersionError,
)

GO_PKG_URL = 'https://pkg.go.dev/{pkg}?tab=versions'
GO_PKG_VERSION_URL = 'https://pkg.go.dev/{pkg}@{version}'


async def get_version(
name: str, conf: Entry, *,
cache: AsyncCache, keymanager: KeyManager,
**kwargs,
) -> VersionResult:
) -> RichResult:
key = tuple(sorted(conf.items()))
return await cache.get(key, get_version_impl)


async def get_version_impl(info) -> VersionResult:
async def get_version_impl(info) -> RichResult:
conf = dict(info)
pkg_name = conf.get('go')

Expand All @@ -31,6 +32,9 @@ async def get_version_impl(info) -> VersionResult:
elements = doc.xpath("//div[@class='Version-tag']/a/text()")
try:
version = elements[0]
return version
return RichResult(
version = version,
url = GO_PKG_VERSION_URL.format(pkg=pkg_name, version=version),
)
except IndexError:
raise GetVersionError("parse error", pkg_name=pkg_name)

0 comments on commit 5140fa2

Please sign in to comment.