# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit go-module

DESCRIPTION="A next-generation crawling and spidering framework"
HOMEPAGE="https://github.com/projectdiscovery/katana https://projectdiscovery.io"
SRC_URI="https://github.com/projectdiscovery/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.gh.tar.gz"
S="${WORKDIR}/${PN}-${PV}"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"

# Go module deps are fetched at build time rather than vendored, so the build
# needs network access; the test suite also reaches the network. RESTRICT grants
# it for this package alone, regardless of the user's FEATURES.
RESTRICT="network-sandbox test"

# Matches the go directive in go.mod.
BDEPEND=">=dev-lang/go-1.26"

src_compile() {
	local katana_ldflags=(
		"-s"
		"-w"
		"-X main.Version=${PV}"
	)

	ego build \
		-trimpath \
		-buildmode=pie \
		-buildvcs=false \
		-ldflags "${katana_ldflags[*]}" \
		-o "${PN}" \
		./cmd/${PN}
}

src_install() {
	newbin "${PN}" "${PN}"

	# Install the man page when upstream ships one.
	if [[ -f man/man1/katana.1 ]]; then
		doman man/man1/katana.1
	fi
}

pkg_postinst() {
	elog "More information:"
	elog "  - Documentation: https://github.com/projectdiscovery/katana"
	elog ""
}