modularviewcontroller

package module
v0.0.0-...-342b1e2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 6 Imported by: 0

README

modularviewcontroller

⚠️ This is currently a work-in-progress library which does not have a stable API. Use with caution. ⚠️

An extremely small and easy-to-use psuedo-MVC (Model-View-Controller) library for server-side Go programs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name string
	// contains filtered or unexported fields
}

func (*App) GET

func (app *App) GET(path string, handler func(*Request, *ResponseWriter))

func (*App) HandleError

func (app *App) HandleError(statusCode int, r *Request, w *ResponseWriter)

func (*App) HandleRoute

func (app *App) HandleRoute(r *Request, w *ResponseWriter)

func (*App) POST

func (app *App) POST(path string, handler func(*Request, *ResponseWriter))

func (*App) Page

func (app *App) Page(path string, handler func(*Request) (int, string))

func (*App) SetErrorHandler

func (app *App) SetErrorHandler(statusCode int, handler func(*Request, *ResponseWriter))

Sets the error handler for a given status code and method type.

func (*App) Use

func (app *App) Use(handler func(*Request, *ResponseWriter) bool)

type Backend

type Backend interface {
	Launch(app App, port int) error
}

type NetHTTPBackend

type NetHTTPBackend struct{}

func (NetHTTPBackend) Launch

func (b NetHTTPBackend) Launch(app App, port int) error

type Request

type Request struct {
	Method     string
	URL        string
	Body       io.ReadCloser
	Headers    http.Header
	RawRequest any // Only use this when you need to.
}

func (*Request) GetJSON

func (r *Request) GetJSON(p any) error

type ResponseWriter

type ResponseWriter struct {
	RawResponseWriter any // Only use this when you need to.
	Headers           map[string]string
	// contains filtered or unexported fields
}

func (*ResponseWriter) Data

func (w *ResponseWriter) Data(statusCode int, contentType string, data []byte)

func (*ResponseWriter) HTML

func (w *ResponseWriter) HTML(statusCode int, data string)

func (*ResponseWriter) JSON

func (w *ResponseWriter) JSON(statusCode int, data map[string]interface{})

func (*ResponseWriter) SetHeader

func (w *ResponseWriter) SetHeader(key string, value string)

func (*ResponseWriter) Status

func (w *ResponseWriter) Status(statusCode int)

func (*ResponseWriter) String

func (w *ResponseWriter) String(statusCode int, contentType string, data string)

func (*ResponseWriter) Text

func (w *ResponseWriter) Text(statusCode int, data string)

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(p []byte) (n int, err error)

func (*ResponseWriter) WriteString

func (w *ResponseWriter) WriteString(p string) (n int, err error)

type RouteHandler

type RouteHandler struct {
	Method string
	Run    func(*Request, *ResponseWriter)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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