gonimbus

package module
v0.0.0-...-b00385c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 8 Imported by: 0

README

Go-nimbus

Go-nimbus is a minimalistic web framework that you can use in your side projects.

Usage

Downloading

   go get github.com/szymon676/go-nimbus
   go mod init
   go mod tidy

Code

Here's an example of how to use Go-nimbus:
package main

import (
	// import go-nimbus as a gonimbus
	gonimbus "github.com/szymon676/go-nimbus"
)

func main() {
	// initialize gonimbus engine
	g := gonimbus.New()
	
	// (optional) use cors to enable frontend fetching data
	g.Use(gonimbus.Cors)
	
	// simple get endpoint that returns "hello"
	g.Get("/", func(c gonimbus.Context) {
		c.String("hello")
	})
	
	// serve your http on port 3000
	g.Serve("3000")
}

Features

Go-nimbus includes the following features:

  • Logging requests (only when you want to)
  • Basic authentication
  • Blazingly fast HTTP methods
  • Easy to use
  • Combination of many different Go frameworks so you can easily adapt to code

Contributing

TODO:

  • Templating

To contribute to Go-nimbus:

  • Navigate to the Go-nimbus project at https://github.com/szymon676/Go-nimbus.
  • Click "Fork".
  • Select the owner of your forked repo.
  • Write the fork name and description.
  • Click "Create fork".
  • Clone your fork and start working on your features.

That's it! With these simple steps, you can start using and contributing to Go-nimbus.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) func(http.Handler) http.Handler

BasicAuth is a middleware that adds basic authentication to the request.

func Cors

func Cors(next http.Handler) http.Handler

func LogRequest

func LogRequest(handler http.HandlerFunc) http.HandlerFunc

Types

type Context

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

func (*Context) BindJSON

func (c *Context) BindJSON(object interface{}) error

BindJSON provides a JSON binding in request

func (*Context) GetCookie

func (c *Context) GetCookie(name string) (*http.Cookie, error)

GetCookie retrieves the cookie with the specified name from the given request Returns the cookie or an error if the cookie is not found

func (*Context) Param

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

func (*Context) Redirect

func (c *Context) Redirect(statuscode int, link string)

Redirect redirects the client to the provided link with the provided status code.

func (*Context) Return

func (c *Context) Return(statuscode int, a ...any) error

Return writes the provided values to the response writer as a string.

func (*Context) SetCookie

func (c *Context) SetCookie(cookie *http.Cookie)

SetCookie sets the given cookie in the response writer's headers

func (*Context) String

func (c *Context) String(statuscode int, prompt string) error

String writes the provided prompt as a string to the response writer.

type Gonimbus

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

func New

func New() *Gonimbus

func (*Gonimbus) Delete

func (g *Gonimbus) Delete(path string, handle HandlerFunc)

Delete registers a DELETE request route with the provided path and handler function.

func (*Gonimbus) Get

func (g *Gonimbus) Get(path string, handle HandlerFunc)

func (*Gonimbus) Head

func (g *Gonimbus) Head(path string, handle HandlerFunc)

Head registers a HEAD request route with the provided path and handler function.

func (*Gonimbus) Patch

func (g *Gonimbus) Patch(path string, handle HandlerFunc)

Patch registers a patch request route with the given path and handler function

func (*Gonimbus) Post

func (g *Gonimbus) Post(path string, handle HandlerFunc)

Post registers a POST request route with the provided path and handler function.

func (*Gonimbus) Put

func (g *Gonimbus) Put(path string, handle HandlerFunc)

Put registers a PUT request route with the provided path and handler function.

func (*Gonimbus) Serve

func (g *Gonimbus) Serve(addr string) error

func (*Gonimbus) Use

func (g *Gonimbus) Use(middleware func(http.Handler) http.Handler)

type HandlerFunc

type HandlerFunc func(c Context)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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