dragon

package module
v1.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: BSD-2-Clause Imports: 9 Imported by: 0

README

Dragon

Golang router package



Install

Run this command to install.

go get github.com/michaelwp/dragon

Examples

package main

import (
	"github.com/michaelwp/dragon"
	"log"
)

type response struct {
	Message string `json:"message"`
}

func main() {
	r := dragon.NewRouter()
	
	api := r.Group("/api/v1")
	api.GET("/home", func(d *dragon.Dragon) error {
		var resp response
		resp.Message = "Hello World"
		return d.ResponseJSON(200, resp)
	})

	log.Fatal(r.Run(":8090"))
}

License

BSD licensed. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	PageNotFound     = "page not found"
	MethodNotAllowed = "method not allowed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dragon

type Dragon struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	Context        context.Context
	Params         map[string]string
	RequestHeader  http.Header
	ResponseHeader http.Header
	Path           string
	Query          url.Values
	RemoteAddress  string
}

func (*Dragon) Body

func (d *Dragon) Body(v interface{}) error

func (*Dragon) GetContext

func (d *Dragon) GetContext(key interface{}) interface{}

func (*Dragon) Next

func (d *Dragon) Next() error

func (*Dragon) ResponseJSON

func (d *Dragon) ResponseJSON(statusCode int, v interface{}) error

func (*Dragon) ResponseStatus

func (d *Dragon) ResponseStatus(statusCode int)

func (*Dragon) ResponseXML

func (d *Dragon) ResponseXML(statusCode int, v interface{}) error

func (*Dragon) SetContext

func (d *Dragon) SetContext(key interface{}, val interface{})

type HandlerFunc

type HandlerFunc func(d *Dragon) error

type Router

type Router interface {
	GET(address string, handlerFunc HandlerFunc)
	POST(address string, handlerFunc HandlerFunc)
	Run(address string) error
	Group(address string) router
	Use(middleware ...HandlerFunc)
}

func NewRouter

func NewRouter() Router

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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