GithubHelp home page GithubHelp logo

zhzluke96 / rango Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 92 KB

🦎minimalist Go app framework.

License: GNU General Public License v3.0

Go 97.91% HTML 0.49% JavaScript 0.04% CSS 0.04% Shell 0.29% Makefile 1.24%

rango's Introduction

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

rango's People

Contributors

zhzluke96 avatar

Stargazers

HuangHaiFeng avatar

Watchers

James Cloos avatar

Forkers

zeta1999

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.