alox

package module
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 7 Imported by: 0

README

Alox

Progress

Interface Implementation Status
Server Server (base)
^ API
^ Website
^ File
^ Proxy
Response (base)
^ JSON
^ Page

Alox (client)

Usage

  1. Install with
    NPM
    npm i --save @alox.sh/client
    or YARN
    yarn add @alox.sh/client
  2. Import
    import type { WebsiteState } from '@alox.sh/client'
    
    // Declare 
    export declare global {
        interface Window {
            __websiteState?: WebsiteState
        }
    }
    

Supported application types

Out of the box support
  • SPA (served from file system) - see examples/spaDir
  • SPA (embeded into the binary) - see examples/spaEmbeded
Extendable
  • Any other type - this library is fully customizable to support virtually any application type

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertHead

func AssertHead(value string, assert func(head string) bool) (passed bool)

func HasPrefix

func HasPrefix(value string, prefix string) bool

func MarshalAndWriteJSON

func MarshalAndWriteJSON(responseWriter http.ResponseWriter, value interface{}) (err error)

func MatchHead

func MatchHead(value string, head string) (matched bool)

func RenderAndWriteHTMLNode

func RenderAndWriteHTMLNode(responseWriter http.ResponseWriter, node *html.Node) (err error)

func ShiftAndAssertHead

func ShiftAndAssertHead(value string, assert func(head string) bool) (passed bool, tail string)

func ShiftAndMatchHead

func ShiftAndMatchHead(value string, head string) (matched bool, tail string)

func ShiftHead

func ShiftHead(value string) (head, tail string)

func Write added in v0.0.14

func Write(
	responseWriter http.ResponseWriter,
	contentType string,
	contentLength int,
	data []byte,
)

func WriteFile

func WriteFile(responseWriter http.ResponseWriter, contentType string, data []byte)

func WriteHTML

func WriteHTML(responseWriter http.ResponseWriter, html []byte)

func WriteJSON

func WriteJSON(responseWriter http.ResponseWriter, json []byte)

func WriteText added in v0.0.14

func WriteText(responseWriter http.ResponseWriter, text []byte)

func WriteXML added in v0.0.14

func WriteXML(responseWriter http.ResponseWriter, xml []byte)

Types

type ContextValues

type ContextValues interface {
	Get(key interface{}) interface{}
	Set(key, value interface{})
	Del(key interface{})
}

type ErrorHandler

type ErrorHandler func(Server, http.ResponseWriter, *http.Request, interface{})

type Filter

type Filter func(*http.Request) bool

type Handler

type Handler func(Server, http.ResponseWriter, *http.Request)

type Middleware

type Middleware func(Handler) Handler

type OnWrite added in v0.0.14

type OnWrite func(*http.Request, string, int, *[]byte)

type ResponseMethods

type ResponseMethods interface {
	Write(
		responseWriter http.ResponseWriter,
		request *http.Request,
		contentType string,
		contentLength int,
		data []byte,
	)

	WriteText(http.ResponseWriter, *http.Request, []byte)
	WriteHTML(http.ResponseWriter, *http.Request, []byte)
	WriteJSON(http.ResponseWriter, *http.Request, []byte)
	WriteXML(http.ResponseWriter, *http.Request, []byte)

	OnWrite(OnWrite)
}

type Server

type Server interface {
	http.Handler
	ResponseMethods

	SetHandler(Handler) Server
	SetErrorHandler(ErrorHandler) Server

	ContextValues() ContextValues

	AddFilters(...Filter) Server
	AddMiddlewares(...Middleware) Server

	Match(*http.Request) bool

	HandleError(http.ResponseWriter, *http.Request, interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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