pbc

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointHealth    = "/api/health"
	EndpointAuthAdmin = "/api/admins/auth-with-password"
	EndpointAuthUser  = "/api/collections/users/auth-with-password"
	EndpointRecords   = "/api/collections/%s/records"
	EndpointRecordID  = "/api/collections/%s/records/%s"
)
View Source
const (
	QTypeData    = "data"
	QTypeExpand  = "expand"
	QTypeFields  = "fields"
	QTypeFilters = "filters"
	QTypeHeaders = "headers"
	QTypePage    = "page"
	QTypeParams  = "params"
	QTypeSort    = "sort"
)

Variables

View Source
var ErrInvalidStatusCode = errors.New("invalid status code")

Functions

func QmListString

func QmListString(ss []string) string

func ResponseTo

func ResponseTo[T any](resp *http.Response) T

Types

type AdminRecord added in v0.0.2

type AdminRecord struct {
	ID      string `json:"id"`
	Created string `json:"created"`
	Updated string `json:"updated"`
	Email   string `json:"email"`
	Avatar  int    `json:"avatar"`
}

type Client

type Client struct {
	BaseURL string
	Token   string
	Client  *clink.Client
}

func New

func New(baseURL string) Client

func (*Client) AdminAuth

func (c *Client) AdminAuth(username, password string) (*http.Response, error)

func (*Client) Auth

func (c *Client) Auth(endpoint, username, password string) (*http.Response, error)

func (*Client) Health added in v0.0.2

func (c *Client) Health() (HealthResponse, error)

func (*Client) RecordCreate

func (c *Client) RecordCreate(name string, opts ...QueryOption) (*http.Response, error)

func (*Client) RecordDelete

func (c *Client) RecordDelete(name string, id string, opts ...QueryOption) (*http.Response, error)

func (*Client) RecordGet

func (c *Client) RecordGet(name string, id string, opts ...QueryOption) (*http.Response, error)

func (*Client) RecordList

func (c *Client) RecordList(name string, opts ...QueryOption) (*http.Response, error)

func (*Client) RecordUpdate

func (c *Client) RecordUpdate(name string, id string, opts ...QueryOption) (*http.Response, error)

func (*Client) Request

func (c *Client) Request(method, url string, opts ...QueryOption) (*http.Response, error)

func (*Client) UserAuth

func (c *Client) UserAuth(username, password string) (*http.Response, error)

type Headers added in v0.0.2

type Headers = map[string]string

Headers represents

type HealthResponse added in v0.0.2

type HealthResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		CanBackup bool `json:"canBackup"`
	} `json:"data"`
}

type Query

type Query struct {
	Headers   map[string]string
	Params    []any
	Data      any
	DataBytes io.Reader
	Filters   string
	Sort      []string
	Fields    []string
	Page      int
	PerPage   int
	SkipTotal bool
	Expand    []string
}

Query represents a query with various options

func NewQuery

func NewQuery(opts ...QueryOption) *Query

NewQuery creates a new Query with the given options

type QueryOption

type QueryOption func(*Query)

QueryOption is a function type for configuring Query

func WithAuthorization added in v0.0.2

func WithAuthorization(token string) QueryOption

WithAuthorization adds Authorization header to request

func WithData

func WithData(data any) QueryOption

WithData adds data to the query

func WithExpand

func WithExpand(expand ...string) QueryOption

WithExpand adds expand options to the query

func WithFields

func WithFields(fields ...string) QueryOption

WithFields adds fields to the query

func WithFilters

func WithFilters(filters string) QueryOption

WithFilters adds filters to the query

func WithHeaders

func WithHeaders(headers Headers) QueryOption

WithHeaders adds headers to the query

func WithPage

func WithPage(page, perPage int, skipTotal bool) QueryOption

WithPage adds pagination to the query

func WithParams

func WithParams(params ...any) QueryOption

WithParams adds parameters to the query

func WithSort

func WithSort(sort ...string) QueryOption

WithSort adds sort options to the query

type RecordBase

type RecordBase struct {
	ID             string `json:"id"`
	CollectionID   string `json:"collectionId"`
	CollectionName string `json:"collectionName"`
	Updated        string `json:"updated"`
	Created        string `json:"created"`
}

type Records

type Records[T any] struct {
	Page       int `json:"page"`
	PerPage    int `json:"perPage"`
	TotalItems int `json:"totalItems"`
	TotalPages int `json:"totalPages"`
	Items      []T `json:"items"`
}

type RequestAuth

type RequestAuth struct {
	Identity string `json:"identity"`
	Password string `json:"password"`
}

type RequestUserCreate added in v0.0.2

type RequestUserCreate struct {
	Username        string `json:"username"`
	Email           string `json:"email"`
	Password        string `json:"password"`
	PasswordConfirm string `json:"passwordConfirm"`
}

type ResponseAdminAuth added in v0.0.2

type ResponseAdminAuth struct {
	Token string      `json:"token"`
	Admin AdminRecord `json:"admin"`
}

type ResponseAuth

type ResponseAuth struct {
	Token  string     `json:"token"`
	Record UserRecord `json:"record"`
}

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

type UserRecord

type UserRecord struct {
	ID              string `json:"id"`
	CollectionID    string `json:"collectionId"`
	CollectionName  string `json:"collectionName"`
	Created         string `json:"created"`
	Updated         string `json:"updated"`
	Username        string `json:"username"`
	Name            string `json:"name"`
	Email           string `json:"email"`
	Verified        bool   `json:"verified"`
	EmailVisibility bool   `json:"emailVisibility"`
}

Jump to

Keyboard shortcuts

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