rocket

package module
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2017 License: MIT Imports: 7 Imported by: 0

README

rocket

Build Status Go Report Card Coverage Status GoDoc
Rocket is a web framework inspired by rocket-rs.

Install

Use go get.
go get github.com/dannypsnl/rocket

Usage

example

You can find example at example folder.

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

var hello = rk.Get("/name/:name/age/:age", func(ctx rk.Ctx) rk.Res {
    return fmt.Sprintf("Hello, %s.\nYour age is %s.", ctx["name"], ctx["age"])
})

var static = rk.Get("/*path", func(ctx rk.Ctx) rk.Res {
    return "static"
})

var API = rk.Post("/", func(ctx rk.Ctx) rk.Res {
    return "Something..."
})
  • First argument of handler creator function is a suffix for routing.
  • context help you get parameters those you interest in request URL.
  • Get, Post function match http method.
Mount and Start
rocket.Ignite(":8080"). // Setting port
    Mount("/", index).
    Mount("/", static).
    Mount("/hello", hello).
    Launch() // Start Serve
  • func Ignite get a string to describe port.
  • Launch start the server.
  • Mount receive a prefix route and a routes.Handler to handle route.
Note
  • Base route can't put parameters part. That is illegal route.
  • You can use fmt.Print to get serialize state of rocket. Because I implement String method for it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v0.7.1

func Delete(route string, do handleMethod) *handler

Delete return delete handler.

func Get added in v0.5.0

func Get(route string, do handleMethod) *handler

Get return a get handler.

func Post added in v0.7.0

func Post(route string, do handleMethod) *handler

Post return a post handler.

func Put added in v0.7.1

func Put(route string, do handleMethod) *handler

Put return a put handler.

Types

type Ctx added in v0.11.0

type Ctx map[string]string

Ctx create by request infomation

Help you access but don't need to detect where it came from

type Res added in v0.10.0

type Res string

Res is response message type

TODO: It will contain some method to help you create response

type Rocket

type Rocket struct {
	// contains filtered or unexported fields
}

Rocket is our service.

func Ignite

func Ignite(port string) *Rocket

Ignite initial service by port.

func (*Rocket) Launch

func (rk *Rocket) Launch()

Launch shoot our service.(start server)

func (*Rocket) Mount

func (rk *Rocket) Mount(route string, h *handler) *Rocket

Mount add handler into our service.

func (*Rocket) String added in v0.9.0

func (rk *Rocket) String() string

String serialize info of our service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL