api

package
v0.0.0-...-2680ed1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonMiddleware

func CommonMiddleware(next http.Handler) http.Handler

CommonMiddleware --Set content-type

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, status int)

func DeletePost

func DeletePost(j *API, path, col, id string)

Delete data from the database

func ErrorLog

func ErrorLog(err error)

func Handler

func Handler(a *API) http.Handler

func InterceptHandler

func InterceptHandler(next http.Handler, errH ErrorHandler) http.Handler

func ReadData

func ReadData(j *API, path string) [][]byte

ReadCoins reads in all coin data in and converts to bytes for unmarshalling

func ReadPost

func ReadPost(j *API, path, col, id string) mod.Post

// ReadData appends 'data' path prefix for a database read

func ReadPostCollection

func ReadPostCollection(j *API, path, col string) []mod.Post

Read all items from the database, unmarshaling the response.

Types

type API

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

Driver is what is used to interact with the scribble database. It runs transactions, and provides log output

func NewAPI

func NewAPI(path string, options *Options) (*API, error)

New creates a new scribble database at the desired directory location, and returns a *Driver to then use for interacting with the database

func (*API) CreatePostHandler

func (a *API) CreatePostHandler(w http.ResponseWriter, r *http.Request)

Create appends post path prefix for a database write

func (*API) Delete

func (j *API) Delete(collection, resource string) error

Delete locks that database and then attempts to remove the collection/resource specified by path

func (*API) DeletePostHandler

func (j *API) DeletePostHandler(w http.ResponseWriter, r *http.Request)

Delete data from the database

func (*API) Host

func (a *API) Host(h string) *API

Change host of API

func (*API) Read

func (j *API) Read(collection, resource string, v interface{}) error

Read a record from the database

func (*API) ReadAll

func (j *API) ReadAll(collection string) ([]string, error)

ReadAll records from a collection; this is returned as a slice of strings because there is no way of knowing what type the record is.

func (*API) ReadPostCollectionHandler

func (j *API) ReadPostCollectionHandler(w http.ResponseWriter, r *http.Request)

Rresponse Handler.

func (*API) ReadPostHandler

func (j *API) ReadPostHandler(w http.ResponseWriter, r *http.Request)

// Response Handler

func (*API) UpdatePost

func (a *API) UpdatePost(path, col, id string, post mod.Post) error

Update appends post path prefix for a database write

func (*API) UpdatePostHandler

func (a *API) UpdatePostHandler(w http.ResponseWriter, r *http.Request)

Update appends post path prefix for a database write

func (*API) Write

func (j *API) Write(collection, resource string, v interface{}) error

Write locks the database and attempts to write the record to the database under the [collection] specified with the [resource] name given

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, int)

type Logger

type Logger interface {
	Fatal(string, ...interface{})
	Error(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})
	Trace(string, ...interface{})
}

Logger is a generic logger interface

type Options

type Options struct {
	Logger // the logger scribble will use (configurable)
}

Options uses for specification of working golang-scribble

type Post

type Post struct {
	ID      string `schema:"id,required"`
	Title   string
	Slug    string
	Date    time.Time
	Excerpt string
	Active  bool
	Order   int
}

Post contains articles and pages used by the CMS

type Posts

type Posts []Post

func (Posts) Len

func (p Posts) Len() int

func (Posts) Less

func (p Posts) Less(i, j int) bool

func (Posts) Swap

func (p Posts) Swap(i, j int)

Jump to

Keyboard shortcuts

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