Light-weight web framework for Go
Clone or download
dannypsnl and shana0440 (#92) fix: 405 response message (#93)
resolve #92 

* fix: 405 response message

* fix: import fmt
Latest commit 1bd03e0 Oct 12, 2018
Permalink
Failed to load latest commit information.
cookie (#43) add: create new cookie by `Cookies.Add(*http.Cookie)` (#73) Sep 26, 2018
example refactor: response headers part (#77) Sep 27, 2018
response Improve coverage (#79) Sep 29, 2018
.codecov.yml (#16) feat: supports more type for context (#19) Aug 25, 2018
.gitignore Create ignore file for git. Oct 10, 2017
.travis.yml (#88) fix: 403 handler bug, forget set offset caused panic (#89) Oct 8, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Aug 29, 2018
CONTRIBUTING.md Create CONTRIBUTING.md Aug 29, 2018
LICENSE Create LICENSE Oct 9, 2017
benchmarks_test.go refactor: move response to sub package named resp (#75) Sep 21, 2018
cookies.go (#43) add: create new cookie by `Cookies.Add(*http.Cookie)` (#73) Sep 26, 2018
duplicated_route_test.go Improve coverage (#79) Sep 29, 2018
go.mod add: go mod tidy Sep 20, 2018
go.sum add: go mod tidy Sep 20, 2018
go.test.sh test: ci Aug 14, 2018
handler.go (#92) fix: 405 response message (#93) Oct 12, 2018
handler_creator.go (#88) fix: 403 handler bug, forget set offset caused panic (#89) Oct 8, 2018
headers.go refactor: move response to sub package named resp (#75) Sep 21, 2018
helper.go (#43) allow user get all cookies (#62) Sep 18, 2018
http_method_test.go (#40) refactor: split test (#55) Sep 9, 2018
parse_test.go test: add uint64 test Aug 25, 2018
readme.md doc: add document link in README Sep 26, 2018
rocket.go Improve coverage (#79) Sep 29, 2018
router.go (#92) fix: 405 response message (#93) Oct 12, 2018
server_test.go (#90) fix: should return 405 when method not allowed (#91) Oct 8, 2018

readme.md

rocket

Build Status Go Report Card codecov GoDoc

Rocket is a web framework inspired by rocket-rs.

Document: https://dannypsnl.github.io/rocket

Install

go get github.com/dannypsnl/rocket

Usage

Import

package example

import (
    rk "github.com/dannypsnl/rocket"
)

Create Handler

package example

import (
	"fmt"
	
	rk "github.com/dannypsnl/rocket"
)

type User struct {
	Name string `route:"name"`
	Age int `route:"age"`
}

var hello = rk.Get("/name/:name/age/:age", func(u *User) string {
    return fmt.Sprintf(
    	"Hello, %s.\nYour age is %d.",
    	u.Name, u.Age)
})
  • First argument of handler creator is a route string can have variant part.
  • Second argument is handler function.
    • handler function can have a argument, that is a type you define to be request context Tag in your type will load request value into it!
      • route tag is route:"name", if route contains /:name, then value is request URL at this place e.g. /Danny will let value of name is string Danny
      • form tag is form:"key", it get form value from form request
      • json tag is json:"key", it get POST/PUT body that is JSON
    • return type of handler function is meaningful
      • Html: returns text as HTML(set Content-Type to text/html)
      • Json: returns text as JSON(set Content-Type to application/json)
      • string: returns text as plain text(set Content-Type to text/plain)
  • handler creator name is match to HTTP Method

Mount and Start

rocket.Ignite(":8080"). // Setting port
    Mount("/", index, static).
    Mount("/hello", hello).
    Launch() // Start Serve
  • func Ignite get a string to describe port.
  • Launch start the server.
  • Mount receive a base route and a handler that exactly handle route. you can emit 1 to N handlers at one Mount
Note
  • Base route can't put parameters part. That is illegal route.