Go Other
Switch branches/tags
Nothing to show
Clone or download
kirillDanshin fix fasthttp.Server usage
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
Latest commit f87026d Aug 13, 2018
Permalink
Failed to load latest commit information.
docs 1.1.0-rc17 Aug 8, 2018
grypto πŸ“„ add licence header Apr 16, 2018
infrastructure 🎨 Format of the imports and vars block Apr 11, 2018
metrics ♻️ Refactoring and formating code Apr 11, 2018
mw/xhostname 1.1.0-rc16 Aug 6, 2018
pprof 🎨 Format of the imports and vars block Apr 11, 2018
test router/SPAIndex: fix test Jul 13, 2018
third_party_licenses 🚚 Moved third_party/ to third_party_licenses/ Apr 11, 2018
x ⚠️ 1.1.0-rc11 BREACKING CHANGE: client and sqlgen moved to 'x' subpac… Jun 15, 2018
.gitignore .gitignore: ignore .idea Sep 28, 2017
.gometalinter.json add apex/log adapter for valyala/fasthttp.Logger, fix gometalinter wa… Feb 10, 2018
.test.sh tests: trying to make tests faster Jun 15, 2018
.travis.yml tests: trying to make tests faster Jun 15, 2018
LICENSE license: fix name Feb 13, 2017
adaptor.go ♻️ Refactoring and formating code Apr 11, 2018
app.go 1.1.0-rc15 Jul 23, 2018
app_copyServer.go fix fasthttp.Server usage Aug 13, 2018
app_handler.go 1.1.0-rc17 Aug 8, 2018
app_healthcheck.go πŸ“„ add licence header Apr 16, 2018
app_listenAndServe.go fix fasthttp.Server usage Aug 13, 2018
app_listenAndServeAll.go πŸ“„ add licence header Apr 16, 2018
app_listenAndServeAutoTLS.go fix fasthttp.Server usage Aug 13, 2018
app_protection.go πŸŽ‰ 1.1.0-rc10 Jun 15, 2018
app_router.go 🎨 refactoring router Apr 16, 2018
app_serve.go fix fasthttp.Server usage Aug 13, 2018
const.go ctx/DecodeGQL: support short json CT Jul 13, 2018
context.go πŸ› Fixed BadRequest output Aug 10, 2018
context_Auth.go πŸ“„ add licence header Apr 16, 2018
context_logHeaders.go πŸ“„ add licence header Apr 16, 2018
context_proxy.go πŸ“„ add licence header Apr 16, 2018
conv.go πŸ“„ add licence header Apr 16, 2018
cookie.go 1.1.0-rc15 Jul 23, 2018
errors.go 1.1.0-rc13 Jul 13, 2018
fasthttprouter_cache.go πŸ“„ add licence header Apr 16, 2018
fasthttprouter_cache_test.go πŸ“„ add licence header Apr 16, 2018
fasthttprouter_path.go router, app, context: rework the router. now we internally use gramew… Mar 20, 2017
fasthttprouter_router.go fixes #35 Jul 4, 2018
fasthttprouter_router_test.go ⚠️ 1.1.0-rc11 BREACKING CHANGE: client and sqlgen moved to 'x' subpac… Jun 15, 2018
fasthttprouter_tree.go fixes #35 Jul 4, 2018
fasthttprouter_tree_test.go fixes #35 Jul 4, 2018
firewall.go πŸ“„ add licence header Apr 16, 2018
infrastructure.go ⚠️ 1.1.0-rc11 BREACKING CHANGE: client and sqlgen moved to 'x' subpac… Jun 15, 2018
log.go πŸ“„ add licence header Apr 16, 2018
middleware.go πŸ“„ add licence header Apr 16, 2018
nanotime.go πŸ“„ add licence header Apr 16, 2018
nanotime.s πŸ“„ add licence header Apr 16, 2018
new.go 1.1.0-rc14 Jul 17, 2018
new_test.go πŸ“„ add licence header Apr 16, 2018
opts.go fix Jul 17, 2018
regFlags.go ✨ introduced DisableFlags: this allows globally disable default grame… Jun 12, 2018
router.go 1.1.0-rc16 Aug 6, 2018
router_default.go router/SPAIndex: handlers support Jul 13, 2018
router_determineHandler.go 🎨 refactoring router Apr 16, 2018
router_domain.go πŸ“„ add licence header Apr 16, 2018
router_internals.go πŸ“„ add licence header Apr 16, 2018
router_test.go πŸ“„ add licence header Apr 16, 2018
sendfile.go πŸ“„ add licence header Apr 16, 2018
subroute.go fixes #35 Jul 4, 2018
types.go 1.1.0-rc17 Aug 8, 2018
version.go 1.1.0-rc17 Aug 8, 2018

README.md

gramework codecov Build Status CII Best Practices Backers on Open Collective Sponsors on Open Collective FOSSA Status

The Good Framework

Gramework Stats Screenshot

Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware

Useful links and info

If you find it, you can submit vulnerability via k@gramework.win.

Name Link/Badge
Docs GoDoc
Our Jira Jira
Support us with a donation or become a sponsor OpenCollective
Our Telegram chat @gramework
We have #gramework channel in the Gophers Slack https://gophers.slack.com
Our Discord Server https://discord.gg/HkW8DsD
Master branch coverage codecov
Master branch status Build Status
Dev branch coverage codecov
Dev branch status Build Status
CII Best Practices CII Best Practices
Gramework Stats Dashboard for Grafana https://grafana.com/dashboards/3422

What is it?

Fast, highly effective and go-way web framework. You get the simple yet powerful API, we handle optimizations internally. We glad to see your feature requests and PRs, that are implemented as fast as possible while keeping framework high quality. SPA-first, so template engine support is WIP.

Gramework is trusted by such projects as:

Confideal banner

Confideal is a service for making fast and safe international deals through smart contracts on Ethereum blockchain.

With Gramework, we have made a number of improvements:

  • reduced boilerplate code;
  • expedited the development process without cutting neither scope nor performance requirements;
  • reduced the code that needs to be maintained;
  • saved hundreds of hours by using functionality that comes as a part of the framework;
  • optimized costs of service maintenance;
  • took advantage of services' and the implementation code's being scalable.

Project history and "Why?"

Basically, before I've started the project, I need a simple, powerful framework with fair license policy. First I consulted with lawyers, which license to choose, based on the list of packages that I need to use. Next, we discussed what to do in order to do everything as correctly as possible.

Nowadays, net/http-based projects are slow and cost-ineffective, so I just write the basic version.

But.

Those support HTTP/2, but theoretically we can make it work even with fasthttp.

Those also support websockets, but this is already was done.

But. Again.

All our company's solutions are based on fasthttp, so we can use our already stable, optimized solutions.

We can provide stable, faster and more effective functionality with really simple API.

We can support net/http handlers with compatibility layer.

We can support multiple handler signature, allow runtime route registration etc.

And even more We can.


So - why you may want to use it?

  • Gramework is battle-tested
  • Gramework is one of the rare frameworks that can help you serve up to 800k rps even on a 4Gb RAM/i5@2.9GHz/2x1Gbit server
  • Gramework make your projects' infrastructure costs more effective by using as less memory as possible
  • Gramework helps you serve requests faster, and so it helps you increase conversions (source 1, source 2)
  • You can build software faster with simple API
  • You can achieve agile support and get answers to your questions
  • You can just ask a feature and most likely it will be implemented and built in
  • You can contact me and donate for high priority feature
  • You can be sure that all license questions are OK with gramework
  • You can buy a corporate-grade support

API status

Stable, but not frozen: we add functions, packages or optional arguments, so you can use new features, but we never break your projects.

Go >= 1.8 required. Go >= 1.9.4 is the oldest continously tested and supported version.

Please, fire an issue or pull request if you want any feature, you find a bug or know how to optimize gramework even more.

Using Gramework with dep is highly recommended.

TOC

Benchmarks

benchmark

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! πŸ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

3rd-party license info

  • Gramework is now powered by fasthttp and custom fasthttprouter, that is embedded now. You can find licenses in /third_party_licenses/fasthttp and /third_party_licenses/fasthttprouter.
  • The 3rd autoTLS implementation, placed in nettls_*.go, is an integrated version of caddytls, because using it by simple import isn't an option: gramework based on fasthttp, that is incompatible with net/http. In the commit I based on, caddy is Apache-2.0 licensed. It's license placed in /third_party_licenses/caddy. @mholt allow us to copy the code in this repo.

FOSSA Status

Basic usage

Hello world

The example below will serve "hello, grameworld". Gramework will register flag "bind" for you, that allows you to choose another ip/port that gramework should listen:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/", "hello, grameworld")

	app.ListenAndServe()
}

If you don't want support bind flag, pass the optional address argument to ListenAndServe.

NOTE: all examples below will register bind flag.

JSON world ;) Part 1

From version: 1.1.0-rc1

The example below will serve {"hello":"grameworld"} from the map. Gramework will register flag "bind" for you, that allows you to choose another ip/port that gramework should listen:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/", func() map[string]interface{} {
		return map[string]interface{}{
			"hello": "gramework",
		}
	})

	app.ListenAndServe()
}

JSON world. Part 2

From version: 1.1.0-rc1

The example below will serve {"hello":"grameworld"} from the struct. Gramework will register flag "bind" for you, that allows you to choose another ip/port that gramework should listen:

package main

import (
	"github.com/gramework/gramework"
)

type SomeResponse struct {
	hello string
}

func main() {
	app := gramework.New()

	app.GET("/", func() interface{} {
		return SomeResponse{
			hello: "gramework",
		}
	})

	app.ListenAndServe()
}

Serving a dir

The example below will serve static files from ./files:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/*any", app.ServeDir("./files"))

	app.ListenAndServe()
}

Serving prepared bytes

The example below will serve byte slice:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/*any", []byte("some data"))

	app.ListenAndServe()
}

Using dynamic handlers, part 1. Simple JSON response.

The example below will serve JSON:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/someJSON", func(ctx *gramework.Context) {
		m := map[string]interface{}{
			"name": "Grame",
			"age": 20,
		}

		if err := ctx.JSON(m); err != nil {
			ctx.Err500()
		}
	})

	app.ListenAndServe()
}

Using dynamic handlers, part 2. Simple JSON response with service-wide CORS enabled.

The example below will serve JSON with CORS enabled for all routes:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.Use(app.CORSMiddleware())

	app.GET("/someJSON", func(ctx *gramework.Context) {
		m := map[string]interface{}{
			"name": "Grame",
			"age": 20,
		}

		if err := ctx.JSON(m); err != nil {
			ctx.Err500()
		}
	})

	app.ListenAndServe()
}

Using dynamic handlers, part 3. Simple JSON response with handler-wide CORS enabled.

The example below will serve JSON with CORS enabled in the handler:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/someJSON", func(ctx *gramework.Context) {
		ctx.CORS()

		m := map[string]interface{}{
			"name": "Grame",
			"age": 20,
		}

		if err := ctx.JSON(m); err != nil {
			ctx.Err500()
		}
	})

	app.ListenAndServe()
}

Using dynamic handlers, part 4. Simple FastHTTP-compatible handlers.

The example below will serve a string:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/someJSON", func(ctx *fasthttp.RequestCtx) {
		ctx.WriteString("another data")
	})

	app.ListenAndServe()
}

Using dynamic handlers, part 5. Access to fasthttp.RequestCtx from gramework.Context

The example below shows how you can get fasthttp.RequestCtx from gramework.Context and use it:

package main

import (
	"github.com/gramework/gramework"
)

func main() {
	app := gramework.New()

	app.GET("/someJSON", func(ctx *gramework.Context) {
		// same as ctx.WriteString("another data")
		ctx.RequestCtx.WriteString("another data")
	})

	app.ListenAndServe()
}