russell

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 15 Imported by: 0

README

Russell logo

What's Russell?

Russell is a Go web framework wrapped fairly tightly around net/http. It's fairly opinionated in a few regards (you have to structure the templates in a very particular manner) but it's generally just a nicer interface for net/http with a couple fancy features.

Who's Russell?

Russell is a riverfaring pirate who enjoys fishing.

Why Russell?

The Framework
  • Just as capable as net/http itself, with nicer ways to do things
  • Slightly higher level with easy access to low level constructs
  • Panic and error handling for additional safety
  • Fairly easy to integrate into existing projects
  • Built-in support for templating pages with 'global' variables sent to all templates
  • Simple access to configuration data
The Otter
  • He seems like a nice fellow
  • He's blue, which is pretty Go of him
  • The Ruby guys named their only usable framework Sinatra, okay? I can do what I want.
  • What are you, a lawyer?

Example Application

You can find an example application (a simple web application that gets/sets a cookie according to user input) at dww/russell-example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigIsTrue

func ConfigIsTrue(keys ...string) bool

Check if a config value is set and equal to true.

func EnableDebug

func EnableDebug()

func GetConfig

func GetConfig[V any](keys ...string) (*V, bool)

Fetch a key from the root, a section, or a subsection of the config. Returns the value of the key (or nil) and whether or not the key was found.

func GetGlobalTemplateVar

func GetGlobalTemplateVar(key string) any

func Go

func Go() error

Start the server.

func RenderTemplate

func RenderTemplate(name string, args map[string]any) (string, error)

Render a template by its name.

func Route

func Route(pattern string, function HandlerFunc)

Register a new route.

func SetConfigPath

func SetConfigPath(newPath string)

Set the path to the application config file. Note that this will have no effect if the configuration is already loaded or if the CONFIG_PATH environment variable is set.

func SetGlobalTemplateVar

func SetGlobalTemplateVar(key string, value any)

Types

type HandlerFunc

type HandlerFunc func(*OutContext, *InContext) error

type InContext

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

func (InContext) Cookie

func (ctx InContext) Cookie(name string) *http.Cookie

Get a cookie by name. Returns nil on failure.

func (InContext) Form

func (ctx InContext) Form() map[string]string

Get all form data (from either query or body.)

func (InContext) GetFile

func (ctx InContext) GetFile(name string) *multipart.FileHeader

Get uploaded file header. Returns nil on failure.

func (InContext) GetForm

func (ctx InContext) GetForm(name string) string

Get a form value by name. Returns an empty string on failure.

func (InContext) GetHeader

func (ctx InContext) GetHeader(name string) string

Get a header by name. Returns an empty string on failure.

func (InContext) Headers

func (ctx InContext) Headers() map[string]string

Get all headers.

func (InContext) Request

func (ctx InContext) Request() *http.Request

Get the bare net/http request.

func (InContext) URI

func (ctx InContext) URI() url.URL

Get the request URI.

type OutContext

type OutContext struct {

	// public
	Writer      bytes.Buffer
	ContentType string
	Status      int
	// contains filtered or unexported fields
}

The Output Context stores information (headers, new cookies, etc.) which is to be sent in the response.

func (*OutContext) AddCookie

func (ctx *OutContext) AddCookie(name string, value string) *http.Cookie

Add a cookie. Returns the newly created cookie.

func (*OutContext) DeleteCookie

func (ctx *OutContext) DeleteCookie(name string)

Unset a cookie.

func (*OutContext) Redirect

func (ctx *OutContext) Redirect(path string, status int)

func (*OutContext) RenderTemplate

func (ctx *OutContext) RenderTemplate(name string, args map[string]any) error

Render a template out to the client.

func (*OutContext) SetHeader

func (ctx *OutContext) SetHeader(name string, value string)

Set a header.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳