goBottle

package module
v0.0.0-...-593c976 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

README

goBottle

a super simple golang HTTP Toolkit

Apache License 2.0

install

  1. go get gitee.com/huanggefan/goBottle

  2. use go mod

hello world

package main

import (
	"fmt"
	"gitee.com/huanggefan/goBottle"
	"log"
	"net/http"
)

// goBottle func
func hello (ctx *goBottle.HttpContext) {
	fmt.Println(ctx.Request.Method, ctx.Request.URL)
	_, _ = fmt.Fprint(ctx.ResponseWriter, "hello world")
}

func main() { 
    // new Http Handler
    mux := goBottle.New()

    // register route
    mux.GET("/a", hello)

    // new http server
    serve := http.Server{
	    Addr:              "127.0.0.1:8080",
	    Handler:           mux,
    }

    // run
    log.Println("http://127.0.0.1:8080/")
    if err := serve.ListenAndServe(); err != nil {
	    log.Fatalln(err)
    }
}

examples

you can find examples at ./examples directory

Documentation

Index

Constants

View Source
const (
	HttpGet     string = "GET"
	HttpPost    string = "POST"
	HttpPut     string = "PUT"
	HttpPatch   string = "PATCH"
	HttpDelete  string = "DELETE"
	HttpOptions string = "OPTIONS"
	HttpHead    string = "HEAD"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpContext

type HttpContext struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request

	Stopped bool
}

type HttpHandler

type HttpHandler struct {
	RouteMap map[string]map[string]handleChain // URL Method handleChain

	HandleNotFound         func(ctx *HttpContext)
	HandleMethodNotAllowed func(ctx *HttpContext)
	HandleError            func(ctx *HttpContext)
}

func New

func New() *HttpHandler

func (*HttpHandler) DELETE

func (h *HttpHandler) DELETE(url string, handleFuncList ...handleFunc)

func (*HttpHandler) GET

func (h *HttpHandler) GET(url string, handleFuncList ...handleFunc)

func (*HttpHandler) HEAD

func (h *HttpHandler) HEAD(url string, handleFuncList ...handleFunc)

func (*HttpHandler) OPTIONS

func (h *HttpHandler) OPTIONS(url string, handleFuncList ...handleFunc)

func (*HttpHandler) PATCH

func (h *HttpHandler) PATCH(url string, handleFuncList ...handleFunc)

func (*HttpHandler) POST

func (h *HttpHandler) POST(url string, handleFuncList ...handleFunc)

func (*HttpHandler) PUT

func (h *HttpHandler) PUT(url string, handleFuncList ...handleFunc)

func (*HttpHandler) ServeHTTP

func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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