mango

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

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

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 11 Imported by: 0

README

Mango - keep simple, keep easy to use.

GoDoc Go Report Card

Installation

To get the package, execute:

go get gopkg.in/mango.v0

To import this package, add the following line to your code:

import "gopkg.in/mango.v0"

Quick Start

func index(ctx contracts.Context) (int, interface{}) {
	return 200, map[string]interface{}{
		"message": "hello mango",
	}
}

func main() {
	m := mango.Default()
	m.Get("/", index)
	m.Start(":8080")
}

Route Definition

Basic Guide
m.Get("/", index)
m.Post("/", index)
m.Put("/", index)
m.Delete("/", index)
m.Any("/any", index) //GET,POST,PUT,DELETE
Routes Group
m.Group("/api", func(api *mango.GroupRouter) {
	api.Get("/", getApi)
	api.Post("/", postApi)
	api.Put("/", putApi)
	api.Delete("/", deleteApi)
	api.Any("/", anyApi) //GET,POST,PUT,DELETE
})
Nested Routes Group
m.Group("/api", func(api *mango.GroupRouter) {
	api.Group("/v1", func(v1 *mango.GroupRouter) {
		v1.Get("/", getApiV1)
		v1.Post("/", postApiV1)
		v1.Put("/", putApiV1)
		v1.Delete("/", deleteApiV1)
		v1.Any("/", anyApiV1) //GET,POST,PUT,DELETE
	})
})
Route Middleware
func myMiddleware() mango.MiddlerFunc {
	return func(ctx *mango.Context) {

		//do something before route handler executed.

		ctx.Next()

		//do something before response sent to client.
	}
}

m.Use(myMiddleware())

//or

m.Get("/", index, myMiddleware())

//or

m.Group("/api", func(api *mango.GroupRouter){

}, myMiddleware())

Built-in Middlewares

  1. Record
  2. Recovery
  3. Cors
  4. Static
  5. Redirect
  6. Compress
  7. Throttle
  8. ...

Serve Mode

HTTP Mode
m.Start(":8080")
HTTPS Mode
m.StartTLS(":8080", "cert file content", "key file content")
HTTPS with Let's encrypt Mode
m.StartAutoTLS(":8080", "example.org")
Handle HTTP and HTTPS
go m.Start(":http")
m.StartAutoTLS(":https", "example.org")

Benchmark

??? what's that???

License

Based on MIT license.

Documentation

Overview

Package mango is a simple micro framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() contracts.Mango

Default returns an Mango instance that uses few middlewares.

func New

func New() contracts.Mango

New returns an new Mango instance

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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