Giter Site home page Giter Site logo

gramework's Introduction

gramework codecov Build Status

The Good Framework

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.

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.

In our days, 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/[email protected]/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 adding functions, packages or optional arguments, so you can use new features, but we never break your projects.

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

3rd-party license info

  • Gramework is now powered by fasthttp and custom fasthttprouter, that is embedded now. You can find licenses in /3rd-Party Licenses/fasthttp and /3rd-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 /3rd-Party Licenses/caddy. @mholt allow us to copy the code in this repo.

Basic usage

Hello world

The example below will serve "hello, grameworld" and register flag "bind", 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()
}

Serving a dir

The example below will serve static files from ./files and register flag "bind", 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("/*any", app.ServeDir("./files"))

	app.ListenAndServe()
}

Serving prepared bytes

The example below will serve bytes and register flag "bind", 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("/*any", []byte("some data"))

	app.ListenAndServe()
}

Using dynamic handlers, part 1

The example below will serve JSON and register flag "bind", 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("/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

The example below will serve JSON with CORS enabled for all routes and register flag "bind", 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.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

The example below will serve JSON with CORS enabled in the handler and register flag "bind", 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("/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

The example below will serve a string and register flag "bind", 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("/someJSON", func(ctx *fasthttp.RequestCtx) {
		ctx.WriteString("another data")
	})

	app.ListenAndServe()
}

Using dynamic handlers, part 5

The example below shows how you can get fasthttp.RequestCtx from gramework.Context and after that it do the same that in part 3:

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()
}

gramework's People

Contributors

kirilldanshin avatar mholt avatar sanqi avatar vintik100 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.