Coder Social home page Coder Social logo

ace's Introduction

ACE godoc badge gocover badge Build Status Go Report Card

Blazing fast Go Web Framework

image

####Installation

go get github.com/plimble/ace

Import

import "github.com/plimble/ace"

Performance

Ace is very fast you can see on this

##Usage

Quick Start

a := ace.New()
a.GET("/", func(c *ace.C) {
	name := c.Params.ByName("name")
	c.JSON(200, map[string]string{"hello": name})
}
a.Run(":8080")

Default Middleware (Logger, Recovery)

a := ace.Default()
a.GET("/", func(c *ace.C) {
	c.String(200,"Hello ACE")
}
a.Run(":8080")

Router

a.DELETE("/", HandlerFunc)
a.HEAD("/", HandlerFunc)
a.OPTIONS("/", HandlerFunc)
a.PATCH("/", HandlerFunc)
a.PUT("/", HandlerFunc)
a.POST("/", HandlerFunc)
a.GET("/", HandlerFunc)
Example
	a := ace.New()

	a.GET("/", func(c *ace.C){
		c.String(200, "Hello world")
	})

	a.POST("/form/:id/:name", func(c *ace.C){
		id := c.Params.ByName("id")
		name := c.Params.ByName("name")
		age := c.Request.PostFormValue("age")
	})

Response

JSON
	data := struct{
		Name string `json:"name"`
	}{
		Name: "John Doe",
	}
	c.JSON(200, data)
String
	c.String(200, "Hello Ace")
Download
	//application/octet-stream
	c.Download(200, []byte("Hello Ace"))
HTML
	c.HTML("index.html")
Redirect
	c.Redirect("/home")

Group Router

g := a.Group("/people", func(c *ace.C) {
	fmt.Println("before route func")
	c.Next()
})

// /people/:name
g.GET("/:name", func(c *ace.C) {
	c.JSON(200, map[string]string{"TEST": "GET METHOD"})
})

// /people/:name
g.POST("/:name", func(c *ace.C) {
	c.JSON(200, map[string]string{"TEST": "POST METHOD"})
})

Data

Set/Get data in any HandlerFunc

a.Use(func(c *ace.C){
	c.SetData("isLogin", true)
})

a.Get("/", func(c *ace.C){
	isLogin := c.GetData("isLogin").(bool)
	//or get all data
	//c.GetAllData()
})

Middlewares

Ace middleware is implemented by custom handler

type HandlerFunc func(c *C)

#####Example

a := ace.New()
a.Use(ace.Logger())

Built-in Middlewares

Serve Static
a.Static("/assets", "./img")
Session with Gorilla sessions
var store = sessions.NewCookieStore([]byte("something-very-secret"))
a.UseSession("cookie", store, nil)

a.GET("/hello", func(c *ace.C) {
	c.Session.SetString("name", "John Doe")
	fmt.Println(c.Session.GetString("name"))
}
Logger
a.Use(ace.Logger())
Recovery
a.Use(ace.Recovery())

HTML Template Engine

Ace built on renderer interface. So you can use any template engine

type Renderer interface {
	Render(w http.ResponseWriter, name string, data interface{})
}

ACE Middlewares

Name Description
gzip GZIP compress
cors Enable Cross-origin resource sharing (CORS)
sessions Gorilla Sessions
pongo2 Pongo2 Template Engine
csrf Cross Site Request Forgery protection

###Contributing

If you'd like to help out with the project. You can put up a Pull Request.

ace's People

Contributors

nicklasos avatar zier 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.