rango

module
v0.0.0-...-f146465 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: GPL-3.0

README

rango

LICENSE badge Build Status Coverage Status size badge

minimalist Go http server framework

It's like Echo, but it's sweeter (fake)

Index

Overview

解决一些小问题的小玩具。

值得注意的是,在默认的函数处理中,将认为所有的body中都是json数据
当然也对其他特殊格式进行支持,比如文件上传等操作

Install

$ go get github.com/zhzLuke96/Rango

Usage

Hello world

package main

import (
  "net/http"
  "github.com/zhzLuke96/Rango/rango"
)

func main() {
  sev := rango.New("hello")
  sev.Func("/", hello)
  sev.Start(":8080")
}

func hello(vars rango.ReqVars) interface{} {
  return "hello " + vars.GetDefault("name", "world") + " !"
}

GET:

$> curl 127.0.0.1:8080/?name=luke96
{...,data:"hello luke96 !",...}

POST:

$> curl -H "Content-Type:application/json" -X POST --data '{"name": "luke96"}' 127.0.0.1:8080/
{...,data:"hello luke96 !",...}

Example

project in example folder list all rango.functions and common usage to help users get started quickly.

  • require go 1.13, build /www/mouse_rainbow.go,

Middlewares

usage

mid := NewMid(...)
sev.Use(mid)

list

name desc example effect
memCacher Memory-based caching NewMemCacher(60).Mid 将body保存在缓存中 超时设置为60s

Matchers

usage

mat := NewMat(...)
sev.Func("/", fn).AddMatcher(mat)

list

name desc example effect
throttle 限流器 newThrottle(500) 500ms内仅回复一个请求

Compose

matcher 结合 middleware,可以搭配出更复杂的行为

例如 throttlecacher 同时使用时,首先会判断是否被缓存,如果没缓存才调用接下来的serve,并穿过 throttle 决定是否响应。

func fn(vars rango.ReqVars)interface{}{...}

func main(){
  memCacher := middleware.NewMemCacher(10)
  throttle := matcher.newThrottle(500)

  sev := rango.NewSev()

  sev.Use(memCacher.Mid)
  sev.Func("/xxxapi", fn).AddMatcher()

  sev.Use(sev.Router.Mid)

  sev.Start(":8080")
}

Changelog

  • 增加 wasm 支持
  • 修复了一些不常见的 bug
  • 迁移快速原型功能到独立 repo

Todo

  • updata .08h
  • file upload handler
  • add more test.go
  • add more comment
  • Rapid Prototyping
  • example on docker
  • finish guide.md
  • BLOB stream
  • RPC function
  • API Document Generation
  • Test tools
  • ...

LICENSE

GPL-3.0

Directories

Path Synopsis
www
Wasming compile: GOOS=js GOARCH=wasm go build -o main.wasm ./main.go
Wasming compile: GOOS=js GOARCH=wasm go build -o main.wasm ./main.go

Jump to

Keyboard shortcuts

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