gzong

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

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 3 Imported by: 0

README

gzong

Sourcegraph GoDoc Go Report Card Build Status Codecov License

Installation

一个以Go为基础的简单web框架,支持中间件插入,已有3个简单的中间件可集成(basicAuth、logging、session),部分完成单元测试。

demo中简单实现了支持增删查改的用户中心(docker+MongoDB)仅供参考。

Usage

试着写一个hello world,可参照gzong/example/easy.go

package main

import (
	"fmt"
	"github.com/cshwen/gzong"
	"net/http"
)

func main() {
	gz := gzong.New()
	gz.GET("/test", testFunc)
	gz.Run(":8080")
}

func testFunc(w http.ResponseWriter, _ *http.Request) {
	fmt.Fprintln(w, "hello gzong.")
}

然后写完记得先编译下(go build)再启动服务(go run)

# 编译
$ go build
# 启动服务
$ go run gzong/example/easy.go
# 测试服务
$ curl localhost:8080/test

Ps: 还有个已实现好的比较复杂示例gzong/example/complex/complex.go可参照上述流程实操试验下。

TODO

  1. 基础web服务,可启动可正常访问 ✔️

  2. 服务框架化 ✔️

  3. 路由支持 ✔️

  4. 中间件支持 ✔️

  5. logging支持 ✔️

  6. basicAuth支持 ✔️

  7. session支持 ✔️

  8. demo实现 ✔️

  9. MongoDB环境(docker) ✔️

  10. MongoDB CRUD实现(用户中心) ✔️

  11. 测试 ✔️

  12. 文档 ✔️

  13. 汇总 ✔️

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(http.HandlerFunc) http.HandlerFunc

Middleware 自定义的中间件方法,入参出参均为http.HandlerFunc

type Router

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

Router web框架路由核心

func New

func New() (r *Router)

New 创建框架对象并将其返回

func (*Router) Add

func (r *Router) Add(route string, method string, hfc handlerFunc)

Add 为路由添加对应指定地址、方法、处理方法

func (*Router) AddMiddleware

func (r *Router) AddMiddleware(m Middleware)

AddMiddleware 添加中间件

func (*Router) Close

func (r *Router) Close()

Close 关闭服务器

func (*Router) GET

func (r *Router) GET(route string, hfc handlerFunc)

GET 为路由添加指定地址的GET请求的处理方法

func (*Router) POST

func (r *Router) POST(route string, hfc handlerFunc)

POST 为路由添加指定地址的POST请求的处理方法

func (*Router) PUT

func (r *Router) PUT(route string, hfc handlerFunc)

PUT 为路由添加指定地址的PUT请求的处理方法

func (*Router) Run

func (r *Router) Run(addr string)

Run 指定地址/端口号运行其服务

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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