core

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCoreAPIToHandler

func AddCoreAPIToHandler(handler Handler)

AddCoreAPIToHandler constructs an API for recipes

Types

type APICallContext

type APICallContext = gin.Context

APICallContext is a facade for any concrete Context, e.g. gins

type DB added in v0.4.6

type DB interface {
	io.Closer
	Ping() error
}

DB is the interface that all DB implementations have to expose

func NewDatabaseClient added in v0.4.6

func NewDatabaseClient() (DB, error)

NewDatabaseClient builds a client to communicate with a database

type Handler

type Handler interface {
	API(version int16) Routes
	http.Handler
}

Handler is a facade for a HTTP handler and can be implemented by a concrete handler like gin.

func NewHandler

func NewHandler() Handler

NewHandler creates a handler for API calls with a pre-configured ADDRESS

type MongoClient added in v0.4.6

type MongoClient struct {
	Client *mongo.Client
	// contains filtered or unexported fields
}

MongoClient to connect to the mongo database

func (*MongoClient) Close added in v0.4.6

func (m *MongoClient) Close() error

Close the connection to the database

func (*MongoClient) Ping added in v0.4.6

func (m *MongoClient) Ping() error

Ping MongoDB

func (*MongoClient) StartDB added in v0.4.6

func (m *MongoClient) StartDB() error

StartDB initializes the database connection

func (*MongoClient) StopDB added in v0.4.6

func (m *MongoClient) StopDB() (err error)

StopDB closes the connection to the db

type Routes

type Routes interface {
	// Route is created to a specific set of endpoints
	Route(string) Routes
	// GET endpoint is added to the routes set and registers a corresponding handler
	GET(string, func(c *APICallContext))
	// Path returns the base path
	Path() string
	// PATCH endpoint is added to the routes set and registers a corresponding handler
	PATCH(string, func(c *APICallContext))
	// POST endpoint is added to the routes set and registers a corresponding handler
	POST(string, func(c *APICallContext))
	// PUT endpoint is added to the routes set and registers a corresponding handler
	PUT(string, func(c *APICallContext))
	// DELETE endpoint is added to the routes set and registers a corresponding handler
	DELETE(string, func(c *APICallContext))
}

Routes is managing a set of API endpoints. Routes implementation(s) call handler function to perform typical CRUD operations (GET, POST, PATCH, ...).

type Server

type Server struct {
	Address string
	// contains filtered or unexported fields
}

Server interface which extends the http.Server

func NewServer

func NewServer() Server

NewServer creates a new server to listen on the defaultAddress

func NewServerA

func NewServerA(addr string, handler http.Handler) Server

NewServerA creates a new server using a given address to listen to

func NewServerH

func NewServerH(handler http.Handler) Server

NewServerH creates a new server using the default address with a custom handler

func (Server) Close

func (s Server) Close() error

Close the server

func (Server) Run

func (s Server) Run() *sync.WaitGroup

Run the server for the API

type Version

type Version struct {
	// APP is the version of the current app
	App string `json:"app"`
	// API is the MAJOR API Version supported by the app
	API string `json:"api"`
}

Version of the application and the exposed api

func AppVersion

func AppVersion() *Version

AppVersion returns the current major version of the API as well as the applications version

Jump to

Keyboard shortcuts

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