Documentation ¶
Index ¶
Constants ¶
const (
Version = "0.0.1"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AwareShutdown ¶
type AwareShutdown interface {
OnShutdown() error
}
AwareShutdown is an optional interface, when developer need do some finalization on his ghost, implements this, and do finalization in OnShutdown().
type AwareStartup ¶
type AwareStartup interface {
OnStartup() error
}
AwareStartup is an optional interface, when developer need do some initialization on his ghost, implements this, and do initialization in OnStartup().
type Binder ¶
type Binder interface {
Bind(f interface{}) Controller
}
Binder is an optional interface, if developer implements it on his ghost, he will get 50x speedup on controller invoking.
A standard implementation looks like this:
func (g *YourGhost) Bind(f interface{}) ghost.Controller { if ctrl, ok := f.(func(*YourGhost, ghost.Context)(ghost.View, error)); ok { return func(ctx ghost.Context) (ghost.View, error) { return ctrl(g, ctx) } } else { return nil } }
type Context ¶
type Context interface { // Request returns the original HTTP request object. Request() *http.Request // PathVar return the variable value in request path. PathVar(name string) string // Query returns the parameter value in query string. Query(name string) string }
Context describes the request context. TODO:
Currently, I have no idea what methods should Context provide. I will add more methods in future when I think it need. Anyway, you can call Request() to retrieve the original request, and get information from it.
type Controller ¶
type Shell ¶
type Shell interface { // Startup starts up the shell manually, use this when you want to // control the shell lifecycle by yourself. // Otherwise, use Run instead. Startup() error // Shutdown shuts down the shell manually, use this when you want to // control the shell lifecycle by yourself. // Otherwise, use Run instead. Shutdown() // Done returns a read-only error channel, you will get notification // from it when the shell completely shutdown, use this when you // control the shell lifecycle by yourself. // Otherwise, use Run instead. Done() <-chan error // Run automatically runs the shell, and shutdown it when receive specific // OS signals, Run will exit after the shell completely shutdown. // If no signal specified, handles SIGINT and SIGTERM as default. Run(sig ...os.Signal) error }
Shell is a lifeless object, until developer gives an interesting ghost to it.
func Born ¶
func Born(ghost interface{}) Shell
Born creates a Shell with your ghost, and will listen at default network and address: "http://127.0.0.1:8066".