Watch 3 Star 1 Fork 0

@Billcoding / goringGoApache-2.0

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
A simple and lightweight web framework, pure native, no third dependencies, including routes, filters, interceptors, static resource resolution, templates without rendering, parameter presets, parameter validation and global ca... spread retract

Clone or download
Notice: Creating folder will generate an empty file .keep, because not support in Git



A simple and lightweight web framework, pure native, no third dependencies, including routes, filters, interceptors, static resource resolution, templates without rendering, parameter presets, parameter validation and global cache etc.





  1. Git
mkdir -p $GOPATH/src/

cd $GOPATH/src/

git clone goring
  1. GoLand
import ""


Default bind

package main

import (

func main() {
	goring.App().Get("/", func(context goring.Context) {

OR DIY bind

package main

import (

func main() {
	goring.App().Get("/", func(context goring.Context) {
	}).FaviconIco().RunAs("", 8080)




Name Key Config Default Description
WebRoot global.webRoot app.SetWebRoot(WEB_ROOT) Exec DIR The goring app webroot
StaticPattern static.pattern app.SetStaticPattern(STATIC_PATTERN) /static Static resource request URL
StaticPrefix static.prefix app.SetStaticPrefix(STATIC_PREFIX) static Static resource local file prefix
StaticCache static.cache app.SetStaticCache(STATIC_CACHE) true Static resource enable cache
ViewPrefix view.prefix app.SetViewPrefix(VIEW_PREFIX) templates View local file prefix
ViewSuffix view.suffix app.SetViewSuffix(VIEW_SUFFIX) html View local file suffix
ViewCache view.cache app.SetViewCache(VIEW_CACHE) true View enable cache
ValidateErrCode validate.err.code app.SetValidateErrCode(Validate_ERR_CODE) 1 Route field validate err code



Environment Variables Support

  • GORING_HOST overwrites bind addr

  • GORING_PORT overwrites bind port

  • GORING_WEB_ROOT overwrites app webroot

  • GORING_STATIC_CACHE overwrites app static resource cache

  • GORING_VIEW_CACHE overwrites app view cache

Handler Config

Route Types

Type Pattern Examples
Pattern Route /path/subpath /index/id
Variables Route /$var1/$var2 /index/{id}/{name}

Route Methods

Routing is similar to RESTful style mapping

  • N/A using app.Req(PATTERN, HANDLER)

  • GET using app.Get(PATTERN, HANDLER)

  • POST using app.Post(PATTERN, HANDLER)

  • DELETE using app.Delete(PATTERN, HANDLER)

  • PUT using app.Put(PATTERN, HANDLER)

  • PATCH using app.Patch(PATTERN, HANDLER)

Route Methods With Fields

  • N/A using app.ReqWithField(PATTERN, HANDLER, FIELD...)

  • GET using app.GetWithField(PATTERN, HANDLER, FIELD...)

  • POST using app.PostWithField(PATTERN, HANDLER, FIELD...)

  • DELETE using app.DeleteWithField(PATTERN, HANDLER, FIELD...)

  • PUT using app.PutWithField(PATTERN, HANDLER, FIELD...)

  • PATCH using app.PatchWithField(PATTERN, HANDLER, FIELD...)

Favicon Ico Handler

Integrates automatic processing of Favicon Ico requests using app.FaviconIco().

The favicon ico file should be stored at $WEB_ROOT/$STATIC_PREFIX/favicon.ico



Static Resources Registration

Support for static resource registration using app.RegisterStaticRes(FILE_EXT, MIME_TYPE)




The before filter executes first, and the after filter executes after the after interceptor is executed

Filter chain is supported

Filter cannot be returned to clients

  1. Before filter define using app.FilterBefore(PATTERN, HANDLER)

  2. After filter define using app.FilterAfter(PATTERN, HANDLER)




The before interceptor executes after the before filter execution is complete, and the after interceptor executes after the routing handler is performed, so the after interceptor can get results to the routing handler

Using context.Response.GetData() get results to the routing handler

Interceptor chain is supported

  1. Before interceptor define using app.InterceptorBefore(PATTERN, HANDLER)

  2. After interceptor define using app.InterceptorAfter(PATTERN, HANDLER)



Field Preset And Validation

Goring allows the route binding fields to be used in the handler when the route is registered, the fields can be automatically pre-set as required by our requirements, and also support sits to validate the fields

When you create a new field using goring.Field(FIELD_NAME), the pre-set and validation is true. So you don't need to call field.Preset() and field.Validate(), unless you need it.

If the field's validation fails, it will be returned directly

  • Define field default value using field.DefaultVal(DEFAULT_VAL)

  • Need to concat multiple values with one value using field.Concat(true)

  • Define concat rune using field.ConcatRune(CONCAT_RUNE) and default ,

  • Need to split a value into multiple values using field.Split(true)

  • Define split rune using field.SplitRune(SPLIT_RUNE) and default ,

  • Define min number value using field.Min(MIN_VALUE)

  • Define max number value using field.Min(MAX_VALUE)

  • Define min length string value using field.MinLength(MIN_LENGTH)

  • Define max length string value using field.MaxLength(MAX_LENGTH)

  • Define optional values using field.Enums(VALUE...)

  • Define regex pattern validate using field.Regex(PATTERN)



Global Cache

Ready when the service starts and ends when the service is destroyed.

  • Set data into caches using app.SetCache(KEY,DATA)

  • Get data from caches using app.GetCache(KEY)

  • Remove data from caches using app.RemoveCache(KEY)

  • Clear caches using app.ClearCaches()



Multipart Support

Integrated simple file operations.

Before you can get the file, you need to parse the request like context.ParseMultipart(MEMORY_SIZE)

  • Get a multipart file using context.GetMultipartFile(FILE_NAME)

  • Get some multipart files using context.GetMultipartFiles(FILE_NAME)

  • Get multipart file original filename using multipartFile.Filename()

  • Get multipart file size in byte using multipartFile.Size()

  • Get multipart file MIME type in byte using multipartFile.ContentType()

  • Get formdata request a header val using multipartFile.Header(NAME)

  • Get formdata request all headers using multipartFile.Headers()

  • Copy to local disk using multipartFile.Copy(DISK_PATH)



Performance Report

>ab -n 250000 -c 5000 localhost/

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,

Benchmarking localhost (be patient)
Completed 25000 requests
Completed 50000 requests
Completed 75000 requests
Completed 100000 requests
Completed 125000 requests
Completed 150000 requests
Completed 175000 requests
Completed 200000 requests
Completed 225000 requests
Completed 250000 requests
Finished 250000 requests

Server Software:        goring/0.1-beta
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      5000
Time taken for tests:   45.580 seconds
Complete requests:      250000
Failed requests:        0
Total transferred:      46500000 bytes
HTML transferred:       3250000 bytes
Requests per second:    5484.91 [#/sec] (mean)
Time per request:       911.592 [ms] (mean)
Time per request:       0.182 [ms] (mean, across all concurrent reques
Transfer rate:          996.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.8      0     508
Processing:   274  905 134.7    879    1432
Waiting:        0  455 226.5    451    1371
Total:        274  905 134.7    879    1432

Percentage of the requests served within a certain time (ms)
  50%    879
  66%    883
  75%    887
  80%    890
  90%    916
  95%   1374
  98%   1409
  99%   1420
 100%   1432 (longest request)

Comments ( 0 )

Sign in for post a comment


Help Search