All Projects → yuyenews → Beerus

yuyenews / Beerus

Licence: MIT license
Beerus is a web framework developed entirely in go, Based on net/http, it extends the management of routes, adds interceptors, session management, receiving parameters with struct, parameter validation, etc. It also provides WebSocket support to upgrade the http protocol to WebSocket and implement communication.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Beerus

next-test-api-route-handler
🚀✨ Confidently unit test your Next.js API routes/handlers in an isolated Next.js-like environment
Stars: ✭ 150 (+525%)
Mutual labels:  route
airoute
*1、Support routing management without context *2、Support 'non-intrusive parameter passing' routing management *3、Airoute that makes you fall in love with routing management
Stars: ✭ 27 (+12.5%)
Mutual labels:  route
Think
ThinkPHP Framework ——十年匠心的高性能PHP框架
Stars: ✭ 7,681 (+31904.17%)
Mutual labels:  route
FGRoute
Get your device ip address, router ip or wifi ssid
Stars: ✭ 128 (+433.33%)
Mutual labels:  route
route
A fast router for PHP
Stars: ✭ 27 (+12.5%)
Mutual labels:  route
EasyWayLocation
This library contain all utils related to google location. like, getting lat or long, Address and Location Setting dialog, many more...
Stars: ✭ 142 (+491.67%)
Mutual labels:  route
laravel-middleware-cache-response
Laravel中间件-Response缓存
Stars: ✭ 61 (+154.17%)
Mutual labels:  route
vue-error-page
[NO LONGER MAINTAINED] Provides a wrapper for router-view that allows you to show error pages without changing the URL.
Stars: ✭ 52 (+116.67%)
Mutual labels:  route
optimized-route
Website that uses the Google Maps API to create an optimized route between waypoints. (My first website, from 2016).
Stars: ✭ 17 (-29.17%)
Mutual labels:  route
route observer mixin
RouteObserveMixin provides easy access to didPush/didPop/didPushNext/didPopNext.
Stars: ✭ 27 (+12.5%)
Mutual labels:  route
google streetview
A command line tool and module for Google Street View Image API
Stars: ✭ 77 (+220.83%)
Mutual labels:  route
STCRouter
基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。
Stars: ✭ 19 (-20.83%)
Mutual labels:  route
RouteOne
Route for PHP
Stars: ✭ 21 (-12.5%)
Mutual labels:  route
uon
🐨 A tiny 200b route change observer.
Stars: ✭ 83 (+245.83%)
Mutual labels:  route
Router
🍭灵活的组件化路由框架.
Stars: ✭ 1,502 (+6158.33%)
Mutual labels:  route
url-trailing-slash
Allows enforcing URL routes with or without trailing slash
Stars: ✭ 35 (+45.83%)
Mutual labels:  route
lifecycle
Lifecycle support for Flutter widgets.
Stars: ✭ 30 (+25%)
Mutual labels:  route
symfony-route-usage
[READ-ONLY] Detect used and unused Symfony routes
Stars: ✭ 41 (+70.83%)
Mutual labels:  route
Framework
ThinkPHP Framework
Stars: ✭ 2,399 (+9895.83%)
Mutual labels:  route
koii
A simple middleware for displaying routes in an express application
Stars: ✭ 73 (+204.17%)
Mutual labels:  route

Beerus ·

Beerus is a web framework developed entirely in go, Based on net/http, it extends the management of routes, adds interceptors, session management, receiving parameters with struct, parameter validation, etc. It also provides WebSocket support to upgrade the http protocol to WebSocket and implement communication.

Installation

go get github.com/Beerus-go/[email protected]

Documentation

https://beeruscc.com/beerus

Examples

HTTP example

Create a function to manage the routing configuration

func CreateRoute() {
    
    // Any request method can use the parameters of the routing function to receive the request parameters
    // Routing functions must have a return value, supported types: struct, map, array
    route.POST("/example/post", func (param  DemoParam, req commons.BeeRequest, res commons.BeeResponse) (map[string]string, error) {
    
        if xxx {
            return nil, errors.New("The error message you want to return to the front-end")
        }
        
        msg := make(map[string]string)
        msg["msg"] = "success"
        return param, nil
    })
}

// DemoParam If you have a struct like this, and you want to put all the parameters from the request into this struct
type DemoParam struct {
    // You can customize any field
    // the name of the field must be exactly the same as the name of the requested parameter, and is case-sensitive
    TestStringReception  string  `notnull:"true" msg:"TestStringReception Cannot be empty" routes:"/example/put"`
    TestIntReception     int     `max:"123" min:"32" msg:"TestIntReception The value range must be between 32 - 123" routes:"/example/post"`
    TestUintReception    uint    `max:"123" min:"32" msg:"TestUintReception The value range must be between 32 - 123"`
    TestFloatReception   float32 `max:"123" min:"32" msg:"TestFloatReception The value range must be between 32 - 123"`
    TestBoolReception    bool
    TestStringRegReception string `reg:"^[a-z]+$" msg:"TestStringRegReception Does not meet the regular"`
    TestBeeFileReception commons.BeeFile
    
    TestJsonReception []string
}

Start Service

func main() {
    // Interceptors, routes, etc. Loading of data requires its own calls
    routes.CreateRoute()
    
    // Listen the service and listen to port 8080
    beerus.ListenHTTP(8080)
}

Non-JSON modes

func CreateRoute() {

    // Turn off json mode, it is on by default
    route.JsonMode = false
    
	
    // In non-json mode, you need to call the Send function in the res object yourself to return the data
    route.POST("/example/post", func (param  DemoParam, req commons.BeeRequest, res commons.BeeResponse) {
        
        // ----- Only non-json mode requires manual validation -----
        
        // If you're in json mode, you don't need to write the following code
        
        // Separate validation of data in struct, this feature can be used independently in any case and is not limited to the routing layer.
        var result = params.Validation(req, &param, param)
        if result != params.SUCCESS {
            res.SendErrorMsg(1128, result)
            return
        }
        
        // It can respond to any type of data, but for demonstration purposes we are still using json here.
        res.SendJson(`{"msg":"SUCCESS"}`)
    })
}

// DemoParam If you have a struct like this, and you want to put all the parameters from the request into this struct
type DemoParam struct {
    // You can customize any field
    // the name of the field must be exactly the same as the name of the requested parameter, and is case-sensitive
    TestStringReception  string  `notnull:"true" msg:"TestStringReception Cannot be empty" routes:"/example/put"`
    TestIntReception     int     `max:"123" min:"32" msg:"TestIntReception The value range must be between 32 - 123" routes:"/example/post"`
    TestUintReception    uint    `max:"123" min:"32" msg:"TestUintReception The value range must be between 32 - 123"`
    TestFloatReception   float32 `max:"123" min:"32" msg:"TestFloatReception The value range must be between 32 - 123"`
    TestBoolReception    bool
    TestStringRegReception string `reg:"^[a-z]+$" msg:"TestStringRegReception Does not meet the regular"`
    TestBeeFileReception commons.BeeFile
    
    TestJsonReception []string
}

WebSocket example

CreateWebSocketRoute Creating websocket routes

func CreateWebSocketRoute() {
	wroute.AddWebSocketRoute("/ws/test", onConnection, onMessage, onClose)
	wroute.AddWebSocketRoute("/ws/test2", onConnection, onMessage, onClose)
}

// In order to save time, only three functions are used below. In practice, you can configure a set of functions for each wroute

func onConnection(session *wparams.WebSocketSession, msg string) {
	session.SendString("connection success")
}

func onMessage(session *wparams.WebSocketSession, msg string) {
	session.SendString("I got the message.")
}

func onClose(session *wparams.WebSocketSession, msg string) {
    println(msg + "-------------------------------")
}

Start Service

func main() {
    // Interceptors, routes, etc. Loading of data requires its own calls
    routes.CreateRoute()
    routes.CreateWebSocketRoute()
    
    // Listen the service and listen to port 8080
    beerus.ListenHTTP(8080)
}

Complete sample code

Database operations

Beerus-DB

License

Beerus is MIT licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].