ara

package module
v0.0.0-...-9c622b2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2015 License: MIT Imports: 9 Imported by: 3

README

Build Status

Ara

A simple web framework that supports RESTful router rules, and text-based handler configuration(see the following example)

Example

  • Install
go get github.com/araframework/ara
  • Dir structure overview
yourapp
    |_conf
    |   |_router     <-*required
    |_static         <-optional
    |   |_index.html
    |   |_image
    |   |_js
    |   |_fonts
    |   |_css
    |_controller.go
    |_main.go
  • controller.go
package main
import (
    "io"
    "net/http"
    "github.com/araframework/ara"
)

type Controller struct {
    ara.Controller
}

// process /hello
func (c *Controller) MyHandler(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "Hello, 世界")
}

// process /hello/{id}
func (c *Controller) MyHandlerWithId(w http.ResponseWriter, r *http.Request) {
    id := r.Form.Get("id")
    w.Write([]byte(id))
}
  • main.go
package main
import (
    "github.com/araframework/ara"
)

func main() {
    controller := &controller.Controller{}
    
    router := ara.NewRouter()
    router.SetController(controller)
    
    ara.Start(router)
}
  • conf/router
/             FS:static
/hello        MyHandler
/hello/{id}   MyHandlerWithId
  • go build and run the executable file
  • Navigate browser to http://localhost:8600 will show the index.html
  • And http://localhost:8600/hello will show Hello, 世界
  • And http://localhost:8600/hello/abc123 will show abc123

TODO

  • namespace support

Documentation

Index

Constants

View Source
const (
	NODE_STATIC  = iota // normal node, ex: abc in /abc
	NODE_DYNAMIC        // dynamic node, ex: {id} in /abc/{id}
)
View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
)

Variables

This section is empty.

Functions

func Logger

func Logger() *aralog.Logger

func Start

func Start(router *Router)

Types

type Controller

type Controller struct{}

func (*Controller) NotFound

func (c *Controller) NotFound(w http.ResponseWriter, r *http.Request)

type Node

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

func NewNode

func NewNode(name string, nodeType uint, h http.Handler) *Node

func (*Node) String

func (node *Node) String() string

type Router

type Router struct {
	// Configurable Handler to be used when no route matches.
	NotFoundHandler http.Handler
	// contains filtered or unexported fields
}

contains all routes

func NewRouter

func NewRouter() *Router

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

---------------- runtime -------------------- this will run in an incoming http request

func (*Router) SetController

func (router *Router) SetController(impl interface{})

Jump to

Keyboard shortcuts

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