core

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MethodGet    = []string{"GET"}
	MethodPut    = []string{"PUT"}
	MethodPost   = []string{"POST"}
	MethodDelete = []string{"DELETE"}
)
View Source
var EnvironmentVariableName = "SPK_ENV"
View Source
var Version = "1.3.8"

Functions

func AdminOnly

func AdminOnly(ctx *Context) error

AdminOnly checks if a user is an admin.

func BasicAuth

func BasicAuth(ctx *Context) error

BasicAuth checks for basic authentication parameters

func BasicHeaders

func BasicHeaders(ctx *Context) error

BasicHeaders applies our general headers. Forced middleware

func EmptyJson added in v1.3.3

func EmptyJson() map[string]interface{}

func HandleResponseJSON

func HandleResponseJSON(ctx *Context, body []byte, status int) error

HandleResponseJSON handles general responses via JSON.

func HeaderFromCtx

func HeaderFromCtx(ctx *Context, key string) string

HeaderFromCtx returns the requested header from the given fasthttp context

func Limiter

func Limiter(ctx *Context) error

Limiter creates a basic in-memory limiter

func LogRequest

func LogRequest(ctx *Context) error

LogRequest provides a log middleware which logs each request.

Forced middleware

func MethodNotAllowed

func MethodNotAllowed(ctx *Context) error

func NextRequestID

func NextRequestID() string

NextRequestID returns the next request id, which is a unix timestamp.

func NotFoundServer

func NotFoundServer(ctx *Context) error

NotFoundServer is the default 404 handler

func ResponseJson added in v1.3.6

func ResponseJson(ctx *Context, output string, status int, error string) error

ResponseJson creates a body and returns a JSON response

func Status

func Status(ctx *Context) error

Status simply returns a 200 OK

func TeaPot

func TeaPot(ctx *Context) error

TeaPot is a 418 handler easter egg

Types

type Application

type Application struct {
	UUID    string `json:"uuid,omitempty"`
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
	Runtime string `json:"runtime,omitempty"`
}

type Communication

type Communication struct {
	Email Emailer `json:"email"`
}

type Components

type Components struct {
	BigCache  bool `json:"bigCache,omitempty"`
	MemCache  bool `json:"memCache,omitempty"`
	Memory    bool `json:"memory,omitempty"`
	Redis     bool `json:"redis,omitempty"`
	MySQL     bool `json:"mysql,omitempty"`
	HTTPCache bool `json:"HTTPCache,omitempty"`
	Log       bool `json:"log,omitempty"`
	StatsView bool `json:"stats_view"`
}

type Config

type Config struct {
	Application   `json:"application"`
	Components    `json:"components"`
	Server        `json:"server"`
	Middleware    `json:"middleware"`
	Router        `json:"router"`
	Log           `json:"log"`
	Environment   `json:"environment"`
	Persistence   `json:"persistence"`
	Communication `json:"communication"`
	S             mantis.Status
}
var App *Config

func New

func New() *Config

New creates a new App based on Config. It Loads() the config file based on the ENV that is set, then calls Factory() to stand up our application.

func (*Config) Factory

func (c *Config) Factory()

Factory creates our Application and instantiates our services

func (*Config) Load

func (c *Config) Load()

Load takes our Config object and loads our environment defined JSON config

func (*Config) M

func (c *Config) M(method string) []string

func (*Config) Method

func (c *Config) Method(method string) []string

func (*Config) Methods

func (c *Config) Methods() []string

func (*Config) Run

func (c *Config) Run()

Run loads routes and starts the Server.

type Context

type Context = routing.Context

type Emailer

type Emailer struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Host     string `json:"host,omitempty"`
}

type Environment

type Environment struct {
	Environment string `json:"environment,omitempty"`
	Location    string `json:"location,omitempty"`
}

type Handler

type Handler []routing.Handler

type Log

type Log struct {
	Writer   *mantisLog.Log `json:"log,omitempty"`
	Location string         `json:"location,omitempty"`
}

type Middleware added in v1.3.8

type Middleware struct {
	Limiter struct {
		Enabled bool `json:"enabled"`
		Time    int  `json:"time"`
		Max     int  `json:"max"`
	} `json:"limiter"`
	LogRequest struct {
		Enabled bool `json:"enabled"`
	} `json:"log_request"`
	BasicHeaders struct {
		Enabled    bool `json:"enabled"`
		ShowServer bool `json:"show_server"`
	} `json:"basic_headers"`
	AdminOnly struct {
		Enabled bool `json:"enabled"`
	} `json:"admin_only"`
	BasicAuth struct {
		Enabled bool `json:"enabled"`
	} `json:"basic_auth"`
}

type Persistence

type Persistence struct {
	BigCache mantisCache.BigCache `json:"bigCache"`
	MemCache mantisCache.MemCache `json:"memCache"`
	Memory   *mantisCache.Memory  `json:"memory"`
	Redis    mantisDatabase.Redis `json:"redis"`
	MySQL    mantisDatabase.MySQL `json:"mysql"`
	Neo4j    mantisDatabase.Neo4j `json:"neo4J"`
}

type Res

type Res = mantis.Response

type Response

type Response struct {
	Status   string      `json:"status"`
	Error    error       `json:"error"`
	Data     interface{} `json:"data"`
	Metadata metadata    `json:"metadata"`
}

type ResponseConfig added in v1.3.8

type ResponseConfig struct {
	RequestId    bool `json:"request_id"`
	SessionToken bool `json:"session_token"`
}

type Router

type Router struct {
	Routes []route `json:"routes,omitempty"`
	Router *routing.Router
	// contains filtered or unexported fields
}

func (*Router) Delete

func (r *Router) Delete(uri string, handler routing.Handler)

Delete is a shorthand for New() specifically for the DELETE method

func (*Router) Get

func (r *Router) Get(uri string, handler routing.Handler)

Get is a shorthand for New() specifically for the GET method

func (*Router) New

func (r *Router) New(uri string, handler routing.Handler, methods []string, middlewares []routing.Handler)

New appends a new route to our route struct.

func (*Router) Post

func (r *Router) Post(uri string, handler routing.Handler)

Post is a shorthand for New() specifically for the POST method

func (*Router) Put

func (r *Router) Put(uri string, handler routing.Handler)

Put is a shorthand for New() specifically for the PUT method

type Server

type Server struct {
	Address        string         `json:"address,omitempty"`
	Port           string         `json:"port,omitempty"`
	WriteTimeout   time.Duration  `json:"writeTimeout,omitempty"`
	ReadTimeout    time.Duration  `json:"readTimeout,omitempty"`
	MemCacheTime   time.Duration  `json:"memCacheTime,omitempty"`
	ResponseConfig ResponseConfig `json:"response_config"`
}

Jump to

Keyboard shortcuts

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