dragon

package module
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: BSD-2-Clause Imports: 12 Imported by: 0

README

Dragon 🐉

Open Source Love     Star Badge

Dragon is a simple 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.


Show some ❤️ by starring the repository!

footer

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ServeStaticFile

func ServeStaticFile(dir string)

ServeStaticFile will reading and serving index1.html file in specific folder as requested in argument

example :
	r := dragon.NewRouter()
	r.ServeHTTPFile("./static")

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

Body mapping body request

func (*Dragon) GetContext

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

func (*Dragon) Next

func (d *Dragon) Next() error

func (*Dragon) ResponseHTML

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

func (*Dragon) ResponseJSON

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

func (*Dragon) ResponseJavaScript

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

func (*Dragon) ResponseStatus

func (d *Dragon) ResponseStatus(statusCode int)

func (*Dragon) ResponseText

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

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)
	PUT(address string, handlerFunc HandlerFunc)
	PATCH(address string, handlerFunc HandlerFunc)
	DELETE(address string, handlerFunc HandlerFunc)
	Run(address string) error
	Group(address string) router
	Use(middleware ...HandlerFunc)
}

func NewRouter

func NewRouter() Router

Directories

Path Synopsis
example
basic command
middleware command
paramURL command
responseHTML command
serveStaticFile command

Jump to

Keyboard shortcuts

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