npms

package module
v0.0.0-...-7877a89 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2017 License: MIT Imports: 4 Imported by: 0

README

npms

Golang client for the npms.io search API.

Build Status Go Report Card GoDoc

Installation

$ go get gopkg.in/rjz/npms.v0

FAQ

npm in golang?

You don't have to use it!

Usage

See godoc

Documentation

Overview

Package npms implements a client for the npms.io API

See: https://api-docs.npms.io

Index

Examples

Constants

View Source
const MaxSuggestions = 100

MaxSuggestions are the v2/search/suggestions API's default limit

Variables

This section is empty.

Functions

func QueryFloat

func QueryFloat(f float32) *float32

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

func NewClient

func NewClient() *Client

NewClient produces a new Client using sensible defaults

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

Jump to

Keyboard shortcuts

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