package jsonclient
import "github.com/google/certificate-transparency-go/jsonclient"
Package jsonclient provides a simple client for fetching and parsing JSON CT structures from a log.
Index ¶
- type JSONClient
- func New(uri string, hc *http.Client, opts Options) (*JSONClient, error)
- func (c *JSONClient) BaseURI() string
- func (c *JSONClient) GetAndParse(ctx context.Context, path string, params map[string]string, rsp interface{}) (*http.Response, []byte, error)
- func (c *JSONClient) PostAndParse(ctx context.Context, path string, req, rsp interface{}) (*http.Response, []byte, error)
- func (c *JSONClient) PostAndParseWithRetry(ctx context.Context, path string, req, rsp interface{}) (*http.Response, []byte, error)
- type Logger
- type Options
- type RspError
Types ¶
type JSONClient ¶
type JSONClient struct { Verifier *ct.SignatureVerifier // nil for no verification (e.g. no public key available) // contains filtered or unexported fields }
JSONClient provides common functionality for interacting with a JSON server that uses cryptographic signatures.
func New ¶
New constructs a new JSONClient instance, for the given base URI, using the given http.Client object (if provided) and the Options object. If opts does not specify a public key, signatures will not be verified.
func (*JSONClient) BaseURI ¶
func (c *JSONClient) BaseURI() string
BaseURI returns the base URI that the JSONClient makes queries to.
func (*JSONClient) GetAndParse ¶
func (c *JSONClient) GetAndParse(ctx context.Context, path string, params map[string]string, rsp interface{}) (*http.Response, []byte, error)
GetAndParse makes a HTTP GET call to the given path, and attempts to parse the response as a JSON representation of the rsp structure. Returns the http.Response, the body of the response, and an error (which may be of type RspError if the HTTP response was available). It returns an error if the response status code is not 200 OK.
func (*JSONClient) PostAndParse ¶
func (c *JSONClient) PostAndParse(ctx context.Context, path string, req, rsp interface{}) (*http.Response, []byte, error)
PostAndParse makes a HTTP POST call to the given path, including the request parameters, and attempts to parse the response as a JSON representation of the rsp structure. Returns the http.Response, the body of the response, and an error (which may be of type RspError if the HTTP response was available). It does NOT return an error if the response status code is not 200 OK.
func (*JSONClient) PostAndParseWithRetry ¶
func (c *JSONClient) PostAndParseWithRetry(ctx context.Context, path string, req, rsp interface{}) (*http.Response, []byte, error)
PostAndParseWithRetry makes a HTTP POST call, but retries (with backoff) on retryable errors; the caller should set a deadline on the provided context to prevent infinite retries. Return values are as for PostAndParse.
type Logger ¶
type Logger interface { // Printf formats and logs a message Printf(string, ...interface{}) }
Logger is a simple logging interface used to log internal errors and warnings
type Options ¶
type Options struct { // Interface to use for logging warnings and errors, if nil the // standard library log package will be used. Logger Logger // PEM format public key to use for signature verification. PublicKey string // DER format public key to use for signature verification. PublicKeyDER []byte // UserAgent, if set, will be sent as the User-Agent header with each request. UserAgent string // If set, this is sent as the Authorization header with each request. Authorization string }
Options are the options for creating a new JSONClient.
func (*Options) ParsePublicKey ¶
ParsePublicKey parses and returns the public key contained in opts. If both opts.PublicKey and opts.PublicKeyDER are set, PublicKeyDER is used. If neither is set, nil will be returned.
type RspError ¶
RspError represents an error that occurred when processing a response from a server, and also includes key details from the http.Response that triggered the error.
func (RspError) Error ¶
Error formats the RspError instance, focusing on the error.
Source Files ¶
- Version
- v1.3.2 (latest)
- Published
- Jun 13, 2025
- Platform
- linux/amd64
- Imports
- 17 packages
- Last checked
- 2 days ago –
Tools for package owners.