fuse: bazil.org/fuse/fs/fstestutil/spawntest/httpjson Index | Files

package httpjson

import "bazil.org/fuse/fs/fstestutil/spawntest/httpjson"

Package httpjson helps transporting JSON over HTTP.

This might get extracted to a standalone repository, if it proves useful enough.

Index

Package Files

client.go doc.go musteof.go server.go

func ServePOST Uses

func ServePOST(fn interface{}) http.Handler

ServePOST adapts a function to a http.Handler with easy JSON unmarshal & marshal and error reporting.

fn is expected to be of the form

func(context.Context, T1) (T2, error)

or similar with pointers to T1 or T2.

type Resource Uses

type Resource struct {
    // contains filtered or unexported fields
}

Resource represents a JSON-speaking remote HTTP resource.

func JSON Uses

func JSON(client *http.Client, url string) *Resource

JSON helps make a HTTP request to the resource tree at url with JSON request and response bodies.

If client is nil http.DefaultClient will be used.

func (*Resource) Call Uses

func (c *Resource) Call(ctx context.Context, data interface{}, dst interface{}) error

Call a HTTP resource that is expected to return JSON data.

If data is not nil, method is POST and the request body is data marshaled into JSON. If data is nil, method is GET.

The response JSON is unmarshaled into dst.

type TrailingDataError Uses

type TrailingDataError struct {
    Token json.Token
}

TrailingDataError is an error that is returned if there is trailing data after a JSON message.

func (*TrailingDataError) Error Uses

func (t *TrailingDataError) Error() string

Package httpjson imports 8 packages (graph) and is imported by 1 packages. Updated 2019-12-21. Refresh now. Tools for package owners.