api

package module
v0.0.0-...-ca4c118 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(method string, urs string, body io.Reader, tm time.Time, key *keys.EdX25519Key) (*http.Request, error)

NewRequest returns new authorized/signed HTTP request.

func NewRequestWithContext

func NewRequestWithContext(ctx context.Context, method string, urs string, body io.Reader, tm time.Time, key *keys.EdX25519Key) (*http.Request, error)

NewRequestWithContext returns new authorized/signed HTTP request with context.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

Types

type Auth

type Auth struct {
	KID     keys.ID
	Method  string
	URL     *url.URL
	Sig     string
	Message string
}

Auth describes auth for a HTTP request.

func NewAuth

func NewAuth(method string, urs string, tm time.Time, key *keys.EdX25519Key) (*Auth, error)

NewAuth returns auth for an HTTP request. The url shouldn't have ? or &.

func (Auth) Header

func (a Auth) Header() string

Header is header value.

type AuthResult

type AuthResult struct {
	KID       keys.ID
	Method    string
	URL       *url.URL
	Nonce     string
	Timestamp time.Time
}

AuthResult is the authorized result.

func CheckAuthorization

func CheckAuthorization(ctx context.Context, method string, urs string, auth string, mc MemCache, now time.Time) (*AuthResult, error)

CheckAuthorization checks auth header.

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type CreateInviteResponse

type CreateInviteResponse struct {
	Code string `json:"code"`
}

CreateInviteResponse ...

type CreateMessageResponse

type CreateMessageResponse struct {
	ID string `json:"id"`
}

CreateMessageResponse ...

type Error

type Error struct {
	Message string `json:"message,omitempty"`
	Status  int    `json:"status,omitempty"`
}

Error ...

type InviteResponse

type InviteResponse struct {
	Sender    keys.ID `json:"sender"`
	Recipient keys.ID `json:"recipient"`
}

InviteResponse ...

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type MemCache

type MemCache interface {
	// Get returns value at key.
	Get(ctx context.Context, k string) (string, error)
	// Put puts a value at key.
	Set(ctx context.Context, k string, v string) error
	// Expire key.
	Expire(ctx context.Context, k string, dt time.Duration) error
}

MemCache ...

type Message

type Message struct {
	Data []byte `json:"data"`
	ID   string `json:"id"`
}

Message ...

type MessagesResponse

type MessagesResponse struct {
	Messages []*Message          `json:"messages"`
	Metadata map[string]Metadata `json:"md,omitempty"`
	Version  string              `json:"version"`
}

MessagesResponse is the response from messages.

func (MessagesResponse) MetadataFor

func (r MessagesResponse) MetadataFor(msg *Message) Metadata

MetadataFor returns metadata for Message.

type Metadata

type Metadata struct {
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Metadata ...

type Response

type Response struct {
	Error *Error `json:"error,omitempty"`
}

Response ...

type SigchainResponse

type SigchainResponse struct {
	KID        keys.ID             `json:"kid"`
	Metadata   map[string]Metadata `json:"md,omitempty"`
	Statements []*keys.Statement   `json:"statements"`
}

SigchainResponse is the response format for a Sigchain request.

func (SigchainResponse) MetadataFor

func (r SigchainResponse) MetadataFor(st *keys.Statement) Metadata

MetadataFor returns metadata for Signed.

func (SigchainResponse) Sigchain

func (r SigchainResponse) Sigchain() (*keys.Sigchain, error)

Sigchain from response.

type User

type User struct {
	ID         string      `json:"id,omitempty"`
	Name       string      `json:"name,omitempty"`
	KID        keys.ID     `json:"kid,omitempty"`
	Seq        int         `json:"seq,omitempty"`
	Service    string      `json:"service,omitempty"`
	URL        string      `json:"url,omitempty"`
	Status     user.Status `json:"status,omitempty"`
	VerifiedAt int64       `json:"verifiedAt,omitempty"`
	Timestamp  int64       `json:"ts,omitempty"`
	Err        string      `json:"err,omitempty"`
}

User ...

func UserFromResult

func UserFromResult(result *user.Result) *User

UserFromResult returns User from user.Result.

type UserResponse

type UserResponse struct {
	User *User `json:"user"`
}

UserResponse ...

type UserSearchResponse

type UserSearchResponse struct {
	Users []*User `json:"users"`
}

UserSearchResponse ...

Jump to

Keyboard shortcuts

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