Documentation
¶
Overview ¶
Package npms implements a client for the npms.io API
Index ¶
- Constants
- func QueryFloat(f float32) *float32
- func SearchQuery(q string, qualifiers *SearchQualifiers) string
- type Client
- type Package
- type PackageMap
- type PackageResult
- type PackageService
- type QualifierFilter
- type SearchParams
- type SearchQualifiers
- type SearchResult
- type SearchResults
- type SearchService
- type SuggestionsResult
Examples ¶
Constants ¶
const MaxSuggestions = 100
MaxSuggestions are the v2/search/suggestions API's default limit
Variables ¶
This section is empty.
Functions ¶
func QueryFloat ¶
QueryFloat helpfully produces a SearchQualifiers-compatible float pointer
func SearchQuery ¶
func SearchQuery(q string, qualifiers *SearchQualifiers) string
SearchQuery builds a `?q=...` param for the v2/search API
Types ¶
type Client ¶
type Client struct {
BaseURL string
Search SearchService
Package PackageService
}
Client interacts with the npms.io v2 API
type Package ¶
type Package struct {
Name string `json:"name"`
Score *string `json:"scope"`
Version string `json:"version"`
Description *string `json:"description"`
Keywords []string `json:"keywords"`
Links *links `json:"links"`
Author *interface{} `json:"author"`
License *string `json:"license"`
Date *string `json:"date"`
}
Package contains a package description returned by the v2/search API
type PackageMap ¶
type PackageMap map[string]PackageResult
PackageMap indexes results (e.g. by package name)
type PackageResult ¶
type PackageResult struct {
AnalyzedAt string `json:"analyzedAt"`
Collected collected `json:"collected"`
Evaluation evaluation `json:"evaluation"`
Score score `json:"score"`
Error interface{} `json:"error"`
}
PackageResult holds a single result from the v2/package API
type PackageService ¶
type PackageService struct {
// contains filtered or unexported fields
}
PackageService implements npms.io's v2/package API
Example (Get) ¶
package main
import (
"fmt"
"github.com/rjz/npms"
)
func main() {
client := npms.NewClient()
pkg, _, err := client.Package.Get("express")
if err != nil {
fmt.Println("Request failed", err)
}
fmt.Println("score is", pkg.Score.Final)
}
Output:
func (PackageService) Get ¶
func (s PackageService) Get(name string) (pkg *PackageResult, resp *http.Response, err error)
Get returns a single package from the v2/package API
func (PackageService) MGet ¶
func (s PackageService) MGet(names ...string) (results *PackageMap, resp *http.Response, err error)
MGet returns multiple Package definitions using the v2/package/mget API
type QualifierFilter ¶
type QualifierFilter uint32
QualifierFilter defines filter flags for a query
const ( NotDeprecated QualifierFilter = 1 << (32 - 1 - iota) NotUnstable NotInsecure IsDeprecated IsUnstable IsInsecure )
type SearchParams ¶
type SearchParams struct {
Q string `url:"q"`
Size string `url:"size,omitempty"`
From string `url:"from,omitempty"`
}
SearchParams bound a query to the v2/search API
type SearchQualifiers ¶
type SearchQualifiers struct {
Author string
BoostExact bool
Filters QualifierFilter
// Keywords may be excluded py prefixing with a dash: '-test'
Keywords []string
Maintainer string
MaintenanceWeight *float32
PopularityWeight *float32
QualityWeight *float32
ScoreEffect *float32
}
SearchQualifiers represents available flags for the v2/search API
func (SearchQualifiers) String ¶
func (q SearchQualifiers) String() string
String converts the SearchQualifiers to a query string
type SearchResult ¶
type SearchResult struct {
Flags map[string]interface{} `json:"flags"`
SearchScore float32 `json:"searchScore"`
Package `json:"package"`
Score score `json:"score"`
}
SearchResult is a single search result from the v2/search API
type SearchResults ¶
type SearchResults struct {
Results []SearchResult `json:"results"`
Total int `json:"total"`
}
SearchResults wraps the collection of results from the v2/search API
type SearchService ¶
type SearchService struct {
// contains filtered or unexported fields
}
SearchService implements npms.io's v2/search API
func (SearchService) Query ¶
func (s SearchService) Query(params *SearchParams) (results *SearchResults, resp *http.Response, err error)
Query invokes the v2/search API
func (SearchService) Suggestions ¶
func (s SearchService) Suggestions(params *SearchParams) (results []SuggestionsResult, resp *http.Response, err error)
Suggestions invokes the v2/search/suggestions API
type SuggestionsResult ¶
type SuggestionsResult struct {
SearchResult
Highlight *string `json:"highlight"`
}
SuggestionsResult wraps a single suggestion from the v2/search/suggestions API