api

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrGLabCommandNotFound represents an error when the glab command is not found
	ErrGLabCommandNotFound ErrorCode = "GLabCommandNotFound"
	// ErrGLabCommandFailed represents an error when the glab command fails
	ErrGLabCommandFailed ErrorCode = "GLabCommandFailed"

	// EnvGLabCommand is the environment variable name for specifying glab command path
	EnvGLabCommand = "MIRU_GLAB_BIN"
	// DefaultGLabCommand is the default command name for GitLab CLI
	DefaultGLabCommand = "glab"
)

Variables

View Source
var (
	Version       = "0.0.7"
	VersionCommit = ""
)

Version and VersionCommit hold the version information

Functions

func FetchDocumentation

func FetchDocumentation(docSource *DocSource, forceUpdate bool) (string, error)

FetchDocumentation fetches documentation text for the given package from the specified source

func GetLanguageAliases

func GetLanguageAliases() map[string]SourceType

GetLanguageAliases returns a map of language aliases to their documentation source types

Types

type DocSource

type DocSource struct {
	// Type represents the documentation source type (e.g., "pkg.go.dev", "npm", "jsr")
	Type SourceType
	// PackagePath represents the processed package path for the documentation source
	PackagePath string
	// RelatedSources contains links to related documentation sources
	RelatedSources []RelatedSource
	// Homepage represents the package's homepage URL
	Homepage string
}

DocSource represents a documentation source with related sources and homepage

func DetectDocSource

func DetectDocSource(pkgPath string, explicitLang string) DocSource

DetectDocSource attempts to detect the documentation source from a package path If explicitLang is provided, it will be used as an explicit language hint

func FetchCratesReadme

func FetchCratesReadme(pkgPath string) (string, *DocSource, error)

FetchCratesReadme fetches the README content from crates.io Returns the content, DocSource with related sources, and any error

func FetchGitHubReadme

func FetchGitHubReadme(pkgPath string) (string, *DocSource, error)

FetchGitHubReadme fetches the README content from a GitHub repository Returns the content, DocSource with related sources, and any error

func FetchGitLabReadme

func FetchGitLabReadme(pkgPath string) (string, *DocSource, error)

FetchGitLabReadme fetches the README content from a GitLab repository Returns the content, DocSource with related sources, and any error

func FetchNPMReadme

func FetchNPMReadme(pkgPath string) (string, *DocSource, error)

FetchNPMReadme fetches the README content from npm registry Returns the content, DocSource with related sources, and any error

func FetchPkgGoDevReadme added in v0.0.7

func FetchPkgGoDevReadme(pkgPath string) (string, *DocSource, error)

FetchPkgGoDevReadme fetches the README file from pkg.go.dev or the source repository

func FetchRubyGemsReadme

func FetchRubyGemsReadme(pkgPath string) (string, *DocSource, error)

FetchRubyGemsReadme fetches the package information from RubyGems API Returns the formatted documentation and DocSource containing related sources

func (DocSource) GetDocument added in v0.0.6

func (docSource DocSource) GetDocument() (*url.URL, error)

func (DocSource) GetHomepage added in v0.0.6

func (docSource DocSource) GetHomepage() (*url.URL, error)

GetHomepage returns the homepage URL for the package. It first checks RelatedSources for a homepage URL, then falls back to the Homepage field, and finally uses the registry URL as a last resort.

func (DocSource) GetRegistry added in v0.0.6

func (docSource DocSource) GetRegistry() (*url.URL, error)

GetRegistry returns the package registry URL. It first checks RelatedSources for a registry URL, then generates one based on the source type.

func (DocSource) GetRepository added in v0.0.6

func (docSource DocSource) GetRepository() (*url.URL, error)

GetRepository returns the repository URL for the package. It first checks RelatedSources for a repository URL, then generates one from the package path.

func (DocSource) GetURL added in v0.0.6

func (docSource DocSource) GetURL() *url.URL

GetURL returns the URL for viewing the package documentation in a browser. For unsupported sources, it returns the GitHub URL as a fallback.

func (docSource DocSource) OtherLinks() ([]RelatedSource, error)

OtherLinks returns a list of related URLs that are not homepage, repository, or registry URLs.

type DocumentationResult added in v0.0.6

type DocumentationResult struct {
	Content string
	Source  *DocSource
}

DocumentationResult represents the result of a documentation fetch operation

type ErrCode added in v0.0.7

type ErrCode string

Error codes for repository detection

var (
	// ErrRepositoryNotFound represents errors when repository information cannot be found
	ErrRepositoryNotFound ErrCode = "RepositoryNotFound"
	// ErrInvalidMetaTag represents errors when meta tag is invalid or missing
	ErrInvalidMetaTag ErrCode = "InvalidMetaTag"
)

type ErrorCode

type ErrorCode string

ErrorCode defines error types for API operations

const (
	// ErrCratesREADMENotFound represents an error when README is not found
	ErrCratesREADMENotFound ErrorCode = "CratesREADMENotFound"
	// ErrCratesPackageNotFound represents an error when package is not found
	ErrCratesPackageNotFound ErrorCode = "CratesPackageNotFound"
)
const (
	// ErrGHCommandNotFound represents an error when the gh command is not found
	ErrGHCommandNotFound ErrorCode = "GHCommandNotFound"
	// ErrGHCommandFailed represents an error when the gh command fails
	ErrGHCommandFailed ErrorCode = "GHCommandFailed"
	// ErrREADMENotFound represents an error when README is not found
	ErrREADMENotFound ErrorCode = "READMENotFound"

	// EnvGHCommand is the environment variable name for specifying gh command path
	EnvGHCommand = "MIRU_GH_BIN"
	// DefaultGHCommand is the default command name for GitHub CLI
	DefaultGHCommand = "gh"
)
const (
	// ErrDocumentationFetch represents errors that occur during documentation fetching
	ErrDocumentationFetch ErrorCode = "DocumentationFetchError"
)
const (
	// ErrNPMREADMENotFound represents an error when README is not found
	ErrNPMREADMENotFound ErrorCode = "NPMREADMENotFound"
)
const (
	ErrPkgGoDevREADMENotFound ErrorCode = "ErrPkgGoDevREADMENotFound"
)
const (
	// ErrRubyGemsREADMENotFound represents an error when README is not found
	ErrRubyGemsREADMENotFound ErrorCode = "RubyGemsREADMENotFound"
)

func (ErrorCode) ErrorCode

func (c ErrorCode) ErrorCode() string

type GoMetadata added in v0.0.7

type GoMetadata struct {
	Repository *url.URL // Repository URL from go-import meta tag
	Homepage   *url.URL // Homepage URL from go-source meta tag
}

GoMetadata contains metadata extracted from go-import and go-source meta tags

type RelatedSource added in v0.0.6

type RelatedSource struct {
	// Type represents the source type (e.g., SourceTypeGoPkgDev) or RelatedSourceType*
	Type RelatedSourceType
	// URL represents the complete URL to the documentation
	URL string
	// From indicates how this source was discovered: "api", or "document"
	From string
}

RelatedSource represents a related documentation source found in content or API responses

func ExtractRelatedSources added in v0.0.6

func ExtractRelatedSources(content, currentPackage string) []RelatedSource

ExtractRelatedSources finds related documentation sources in the given content by matching URLs and package installation commands. It returns a deduplicated list of RelatedSource entries that match the current package.

type RelatedSourceType added in v0.0.6

type RelatedSourceType string
const (
	RelatedSourceTypeDocumentation RelatedSourceType = "documentation"
	RelatedSourceTypeHomepage      RelatedSourceType = "homepage"
)

func RelatedSourceTypeFromString added in v0.0.6

func RelatedSourceTypeFromString(s string) RelatedSourceType

RelatedSourceTypeFromString creates a SourceType from a string

func (RelatedSourceType) String added in v0.0.6

func (s RelatedSourceType) String() string

String returns the string representation of the RelatedSourceType

type SourceType added in v0.0.6

type SourceType string

SourceType represents the type of documentation source

const (
	// Documentation source types
	SourceTypeGoPkgDev SourceType = "pkg.go.dev"
	SourceTypeJSR      SourceType = "jsr.io"
	SourceTypeNPM      SourceType = "npmjs.com"
	SourceTypeCratesIO SourceType = "crates.io"
	SourceTypeRubyGems SourceType = "rubygems.org"
	SourceTypeGitHub   SourceType = "github.com"
	SourceTypeGitLab   SourceType = "gitlab.com"
	SourceTypeUnknown  SourceType = ""
)

func SourceTypeFromString added in v0.0.6

func SourceTypeFromString(s string) SourceType

SourceTypeFromString creates a SourceType from a string

func (SourceType) ContainRepositoryURL added in v0.0.6

func (s SourceType) ContainRepositoryURL() bool

func (SourceType) IsDocumentation added in v0.0.6

func (s SourceType) IsDocumentation() bool

func (SourceType) IsRegistry added in v0.0.6

func (s SourceType) IsRegistry() bool

IsRegistry returns true if the source type is a package registry

func (SourceType) IsRepository added in v0.0.6

func (s SourceType) IsRepository() bool

IsRepository returns true if the source type is a code repository

func (SourceType) String added in v0.0.6

func (s SourceType) String() string

String returns the string representation of the SourceType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL