Giter Site home page Giter Site logo

gingle-web's Introduction

gingle-web

A simple gin-like web framework implemented by Golang.


Features

  • Serve Static Files
  • Handle Route Mappings (static and dynamic)
  • Middleware Plugin (default and custom)
  • Group Control
  • Context Support
  • Template Render

Quick Start

Initiation

// Get an empty engine with no middlewares
router := gingle.New()

// Get an default engine with Logger() and Recovery() middlewares
router := gingle.Default

Serve Static Files

// Convert relative path to server root
router.Static("relativePath", "root")

Handle Route Mappings

router.GET("/pattern", func(ctx *gingle.Context) {
  // Static Route Mappings in GET method
})

router.POST("/pattern", func(ctx *gingle.Context) {
  // Static Route Mappings in POST method
})

router.PUT("/pattern", func(ctx *gingle.Context) {
  // Static Route Mappings in PUT method
})

router.DELETE("/pattern", func(ctx *gingle.Context) {
  // Static Route Mappings in DELETE method
})

router.GET("/:pattern", func(ctx *gingle.Context) {
  // Dynamic Route Mappings in /:pattern mode

  // Example:
  // Note - parameter `language` will match value `en` as follows
  // Route - /:language/content/
  // URL - http:localhost:8080/en/content/
})

router.GET("/*pattern", func(ctx *gingle.Context) {
  // Dynamic Route Mappings in /*pattern mode

  // Example:
  // Note - parameter `filepath` will match value `static/index.html` as follows
  // Route - /*filepath
  // URL - http:localhost:8080/static/index.html
})

Middleware Plugin

// `mymiddleware.go`: Define a custom middleware
func MyMiddleware() HandlerFunc {
  return func(ctx *Context) {
    // Do something before excuting handler

    ctx.Next()

    // Do something after excuting handler
  }
}

// `main.go`: Apply the middleware
router.Use(MyMiddleware())

Group Control

// Define a router group
api := router.Group("/api")

// Add routes to the router group
{
  api.POST("/signin", func(ctx *Context) {
    // pattern is /api/signin
  })
  api.POST("/signup", func(ctx *Context) {
    // pattern is /api/signup
  })
}

// Apply middlewares to the router group
api.Use(Logger(), Recovery())

TODOs

  • Helpers for PUT and DELETE
  • Regular Expression Support
  • Pratical Middlewares
  • Unit and Benchmark Tests

gingle-web's People

Contributors

lottewong avatar

Watchers

 avatar  avatar

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.