geneva

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 5 Imported by: 0

README

Geneva Web Framework

Go

Geneva is a simple Gin-like web framework written in Golang.

Running Geneva

package main

import (
	"net/http"

	"github.com/demouth/geneva"
)

func main() {
	r := geneva.New()
	v1 := r.Group("/v1")
	v1.GET("/ping", func(c *geneva.Context) {
		c.JSON(http.StatusOK, geneva.H{
			"message": "pong",
		})
	})
	r.Run("127.0.0.1:8080")
}

Documentation

Overview

Package geneva is a simple web framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request
	Params  httprouter.Params
	// contains filtered or unexported fields
}

Context is argument of Handler.

func (*Context) Abort

func (c *Context) Abort()

Abort prevents pending handlers from being called. Note that this will not stop the current handler.

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus calls `Abort()` and writes the headers with the specified status code.

func (*Context) DefaultPostForm

func (c *Context) DefaultPostForm(key, defaultValue string) string

DefaultPostForm returns the specified key from a POST urlencoded form or multipart form when it exists, otherwise it returns the specified defaultValue string. See: PostForm() and GetPostForm() for further information.

func (*Context) DefaultQuery

func (c *Context) DefaultQuery(key, defaultValue string) string

DefaultQuery returns the keyed url query value if it exists, otherwise it returns the specified defaultValue string. See: Query() and GetQuery() for further information.

func (*Context) Get

func (c *Context) Get(key string) (value any, exists bool)

Get returns the value for the given key, ie: (value, true).

func (*Context) GetPostForm

func (c *Context) GetPostForm(key string) (string, bool)

GetPostForm is like PostForm(key). It returns the specified key from a POST urlencoded form or multipart form when it exists `(value, true)` (even when the value is an empty string), otherwise it returns ("", false).

func (*Context) GetQuery

func (c *Context) GetQuery(key string) (string, bool)

GetQuery is like Query(), it returns the keyed url query value if it exists `(value, true)` (even when the value is an empty string), otherwise it returns `("", false)`.

func (*Context) JSON

func (c *Context) JSON(code int, obj any)

JSON serializes the given struct as JSON into the response body.

func (*Context) Next

func (c *Context) Next()

Next should be used only inside middleware. It executes the pending handlers in the chain inside the calling handler.

func (*Context) Param

func (c *Context) Param(key string) string

Param returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

func (*Context) PostForm

func (c *Context) PostForm(key string) string

PostForm returns the specified key from a POST urlencoded form or multipart form when it exists, otherwise it returns an empty string `("")`.

func (*Context) Query

func (c *Context) Query(key string) string

Query is shortcut for `c.Request.URL.Query().Get(key)`

func (*Context) Set

func (c *Context) Set(key string, value any)

Set is used to store a new key/value pair exclusively for this context.

func (*Context) String

func (c *Context) String(code int, msg string)

String writes the given string into the response body.

type Engine

type Engine struct {
	*RouterGroup
	// contains filtered or unexported fields
}

Engine is the framework's instance.

func New

func New() *Engine

New returns a new Root instance.

func (*Engine) Run

func (e *Engine) Run(addr string)

Run listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)

type H

type H map[string]any

H is a shortcut for map[string]any

type Handler

type Handler func(*Context)

Handler defines the handler used by geneva middleware as return value.

func Recovery

func Recovery() Handler

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

type Handlers

type Handlers []Handler

Handlers defines a Handler slice.

type RouterGroup

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

RouterGroup is used internally to configure router.

func (*RouterGroup) DELETE

func (rg *RouterGroup) DELETE(path string, handlers ...Handler)

DELETE is a shortcut for geneva.Handler("DELETE", path, handlers)

func (*RouterGroup) GET

func (rg *RouterGroup) GET(path string, handlers ...Handler)

GET is a shortcut for geneva.Handler("GET", path, handlers)

func (*RouterGroup) Group

func (rg *RouterGroup) Group(relativePath string, handlers ...Handler) *RouterGroup

Group creates a new router group. You should add all the routes that have common middlewares or the same path prefix.

func (*RouterGroup) HEAD

func (rg *RouterGroup) HEAD(path string, handlers ...Handler)

HEAD is a shortcut for geneva.Handler("HEAD", path, handlers)

func (*RouterGroup) Handle

func (rg *RouterGroup) Handle(method, relativePath string, handlers ...Handler)

Handle registers a new request handle and middleware with the given path and method.

func (*RouterGroup) OPTIONS

func (rg *RouterGroup) OPTIONS(path string, handlers ...Handler)

OPTIONS is a shortcut for geneva.Handler("OPTIONS", path, handlers)

func (*RouterGroup) PATCH

func (rg *RouterGroup) PATCH(path string, handlers ...Handler)

PATCH is a shortcut for geneva.Handler("PATCH", path, handlers)

func (*RouterGroup) POST

func (rg *RouterGroup) POST(path string, handlers ...Handler)

POST is a shortcut for geneva.Handler("POST", path, handlers)

func (*RouterGroup) PUT

func (rg *RouterGroup) PUT(path string, handlers ...Handler)

PUT is a shortcut for geneva.Handler("PUT", path, handlers)

func (*RouterGroup) Use

func (rg *RouterGroup) Use(handlers ...Handler)

Use adds middleware to the group.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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