app

package
v0.0.0-...-4e24a5a Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGagaMimes

func InitGagaMimes()

func StaticFileController

func StaticFileController(r *Request, prefix string, dir string, compress bool) string

Types

type Config

type Config struct {
	Server   ServerConfig `json:"server"`
	Database interface{}  `json:"database,omitempty"`
	Log      LogConfig    `json:"log,omitempty"`
	SEO      SEOConfig    `json:"seo,omitempty"`
	Custom   interface{}  `json:"custom,omitempty"`
}

Config is the main configuration struct

func LoadConfig

func LoadConfig() *Config

LoadConfig loads Gaga configurations from the specified file. It automatically allows environment overrides for dev and production as well as for different users on a device.

type Controller

type Controller func(r *Request) string

type DatabaseConfig

type DatabaseConfig struct {
	Engine   string `json:"engine"`
	Host     string `json:"host"`
	Port     int    `json:"port,omitempty"`
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

DatabaseConfig configuration struct

type Gaga

type Gaga struct {
	Config          *Config
	RouteGenerator  func(*Routing)
	NotFoundHandler func(*Request) string
}

Gaga main struct

func (*Gaga) Init

func (g *Gaga) Init()

func (*Gaga) Serve

func (g *Gaga) Serve()

func (Gaga) ServeHTTP

func (g Gaga) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LogConfig

type LogConfig struct {
	// Engine is the device to log into.
	//
	// Options include:
	//  file, console, both
	Engine     string `json:"engine"`
	Path       string `json:"path,omitempty"`
	ShowSource bool   `json:"show_source,omitempty"`

	// Level is the minimum log level to show.
	//
	// Options include:
	//  info, error, warn, trace, fatal, panic.
	Level string `json:"level,omitempty"`
}

LogConfig configuration struct

type Request

type Request struct {
	URI         string
	Method      string
	Header      map[string]string
	Params      map[string]string
	Response    Response
	Writer      http.ResponseWriter
	BaseRequest *http.Request
	// contains filtered or unexported fields
}

Request struct

func (*Request) File

func (r *Request) File(name string) interface{}

func (*Request) Get

func (r *Request) Get(name string) interface{}

func (*Request) Post

func (r *Request) Post(name string) interface{}

type Resource

type Resource interface {
	Create(r *Request)
	Update(r *Request)
	Delete(r *Request)
	View(r *Request)
}

Resource interface is a form of controller that allows you to automatically create and bind CRUD operations to related methods in structs as well as automatically create related and useful routing.

type Response

type Response struct {
	Header      map[string]string
	StatusCode  int
	ContentType string
}

Response struct

type Route

type Route struct {
	Path       string
	Controller Controller
	// contains filtered or unexported fields
}

Route struct

func (*Route) Default

func (r *Route) Default(name string, test string) *Route

Default allows setting a default value to an optional named param

in a route whenever missing.

Example:

r.Default("/{id?}", controller.User).Default("id", "10")

func (*Route) Where

func (r *Route) Where(name string, test string) *Route

Where allows specifying a pattern that a named param in a

route must match to be valid.

Example:

r.Route("/{id}", controller.User).Where("id", `\d+`)

type Routing

type Routing struct {
	Routes map[string][]Route
	// contains filtered or unexported fields
}

Routing struct

func (*Routing) Any

func (r *Routing) Any(path string, controller Controller) *Route

Any allows creation of a route that's bound to all/any request method.

func (*Routing) CreateRoute

func (r *Routing) CreateRoute(method string, path string, controller Controller) *Route

CreateRoute allows you to create a route for any HTTP method bound to a given path.

func (*Routing) Delete

func (r *Routing) Delete(path string, controller Controller) *Route

Delete routes an HTTP DELETE request with a request URI matching the given path to the given controller.

func (*Routing) Get

func (r *Routing) Get(path string, controller Controller) *Route

Get routes an HTTP GET request with a request URI matching the given path to the given controller.

func (*Routing) Head

func (r *Routing) Head(path string, controller Controller) *Route

Head routes an HTTP HEAD request with a request URI matching the given path to the given controller.

func (*Routing) Options

func (r *Routing) Options(path string, controller Controller) *Route

Options routes an HTTP OPTIONS request with a request URI matching the given path to the given controller.

func (*Routing) Patch

func (r *Routing) Patch(path string, controller Controller) *Route

Patch routes an HTTP PATCH request with a request URI matching the given path to the given controller.

func (*Routing) Post

func (r *Routing) Post(path string, controller Controller) *Route

Post routes an HTTP POSt request with a request URI matching the given path to the given controller.

func (*Routing) Put

func (r *Routing) Put(path string, controller Controller) *Route

Put routes an HTTP PUT request with a request URI matching the given path to the given controller.

func (*Routing) Static

func (r *Routing) Static(path string, dir string)

Static routes a request for static files matching the path to the specified directory

func (*Routing) Trace

func (r *Routing) Trace(path string, controller Controller) *Route

Trace routes an HTTP TRACE request with a request URI matching the given path to the given controller.

type SEOConfig

type SEOConfig struct {
	// Compress indicates whether to compress output.
	// The output is only compressed when the requester (most likely
	// a browser supports it through the Accept-Encoding header.
	//
	//  gzip is the default if supported, if not,
	//  deflate will be attempted if supported.
	Compress bool `json:"compress,omitempty"`

	// CompressionThreshold is the minimum response size before
	// response compression sets in for non static files.
	//
	// NOTE:
	//
	//  1. Once compression is enabled, all static files will be
	//     compressed if the request supports it.
	//
	//  2. For very light data (few bytes), compression may increase the
	//     size of the response.
	CompressionThreshold int `json:"compression_threshold,omitempty"`
}

SEOConfig configuration struct

type ServerConfig

type ServerConfig struct {
	Port               int    `json:"port"`
	ListenOn           string `json:"listen_on"`
	Secure             bool   `json:"secure,omitempty"`
	TLSCertificateFile string `json:"tls_certificate_file,omitempty"`
	TLSKeyFile         string `json:"tls_key_file,omitempty"`
}

ServerConfig configuration struct

type Template

type Template struct {
	Path string
}

Jump to

Keyboard shortcuts

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