api

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package api describes microservice example's public JSON-RPC 2.0 API.

Index

Constants

View Source
const Name = "RPC"

Name is a net/rpc type name used as a prefix before method names.

Variables

View Source
var (
	ErrTryAgainLater   = jsonrpc2.NewError(-503, "temporary error")   // Safe to resend.
	ErrTooManyRequests = jsonrpc2.NewError(-429, "too many requests") // Safe to resend (after delay).
	ErrNotFound        = jsonrpc2.NewError(-404, "not found")         // Given ID does not exists.
	ErrForbidden       = jsonrpc2.NewError(-403, "forbidden")         // Not allowed by permissions.
	ErrUnauthorized    = jsonrpc2.NewError(-401, "unauthorized")      // Missing or invalid Ctx.AccessToken.
)

All generic errors which may be returned by RPC methods.

ErrsCommon may be returned by any RPC method.

View Source
var ErrsExtra = map[string][]error{
	Name + ".Example":    {ErrNotFound},
	Name + ".IncExample": nil,
}

ErrsExtra list non-common errors which may be returned by concrete RPC method.

Functions

This section is empty.

Types

type Ctx

type Ctx = apix.JSONRPC2Ctx

Ctx must be embedded and tagged `json:"Ctx"` to prevent JSON embedding.

type Example

type Example struct {
	Counter   int
	UpdatedAt time.Time
}

Example is an example of user's data.

type RPCExampleReq

type RPCExampleReq struct {
	Ctx      `json:"Ctx"`
	UserName string
}

RPC.Example returns given user's Example.

type RPCExampleResp

type RPCExampleResp = Example

type RPCIncExampleReq

type RPCIncExampleReq struct {
	Ctx `json:"Ctx"`
}

RPC.IncExample increments user's Example.

type RPCIncExampleResp

type RPCIncExampleResp struct{}

Jump to

Keyboard shortcuts

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