Documentation ¶
Overview ¶
Package horo is context friendly, Simple Web framework.
Basic Example:
package main import ( "net/http" "golang.org/x/net/context" "github.com/k2wanko/horo" "github.com/k2wanko/horo-middleware" ) func Index(c context.Context) error { return horo.Text(c, http.StatusOK, "Hello World!") } func main() { h := horo.New() h.Use(middleware.Logger(), middleware.Recover()) h.GET("/", Index) h.ListenAndServe(":8080") }
Google App Engine Example:
package main import ( "net/http" "golang.org/x/net/context" "github.com/k2wanko/horo" "github.com/k2wanko/horo-middleware" ) func Index(c context.Context) error { return horo.Text(c, 200, fmt.Sprintf("Hello, %s", appengine.AppID(c))) } func init() { h := horo.New() h.Use(middleware.Recover(), middleware.AppContext()) h.GET("/", Index) http.Handle("/", h) }
Example (Appengine) ¶
package main import ( "net/http" "github.com/k2wanko/horo" "golang.org/x/net/context" ) func main() { // Write in func init() h := horo.New() h.GET("/", func(c context.Context) error { return horo.Text(c, 200, "Hello, World") }) http.Handle("/", h) }
Output:
Example (Basic) ¶
h := horo.New() h.Use(middleware.Logger()) h.GET("/", func(c context.Context) error { return horo.Text(c, 200, "Hello, World") }) h.ListenAndServe(":8080")
Output:
Index ¶
- Variables
- func DefaultErrorHandler(c context.Context, err error)
- func HTML(c context.Context, code int, html string) (err error)
- func JSON(c context.Context, code int, i interface{}) (err error)
- func MethodNotAllowed(c context.Context) error
- func NoContent(c context.Context, code int) error
- func NotFound(c context.Context) error
- func Param(c context.Context, name string) (v string)
- func Redirect(c context.Context, code int, url string) error
- func Request(c context.Context) (r *http.Request)
- func RequestID(ctx context.Context) (id string)
- func Text(c context.Context, code int, s string) (err error)
- type ErrorHandlerFunc
- type HTTPError
- type HandlerFunc
- type Horo
- func (h *Horo) DELETE(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) GET(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) HEAD(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) ListenAndServe(addr string) error
- func (h *Horo) OPTIONS(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) PATCH(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) POST(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) PUT(path string, hf HandlerFunc, mw ...MiddlewareFunc)
- func (h *Horo) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Horo) Use(mw ...MiddlewareFunc)
- type MiddlewareFunc
- type RequestIDGenerator
- type ResponseWriter
- func (r *ResponseWriter) CloseNotify() <-chan bool
- func (r *ResponseWriter) Committed() bool
- func (r *ResponseWriter) Flush()
- func (r *ResponseWriter) Header() http.Header
- func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *ResponseWriter) Reset(w http.ResponseWriter)
- func (r *ResponseWriter) Size() int64
- func (r *ResponseWriter) Status() int
- func (r *ResponseWriter) Write(b []byte) (n int, err error)
- func (r *ResponseWriter) WriteHeader(code int)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotContext is thrown if the context does not have Horo context. ErrNotContext = errors.New("Not Context") // ErrInvalidRedirectCode is thrown if invalid redirect code. ErrInvalidRedirectCode = errors.New("invalid redirect status code") )
Functions ¶
func DefaultErrorHandler ¶
DefaultErrorHandler invoke HTTP Error Handler
func MethodNotAllowed ¶
MethodNotAllowed is default MethodNotAllowed handler.
Types ¶
type ErrorHandlerFunc ¶
ErrorHandlerFunc is error handling function.
type HandlerFunc ¶
HandlerFunc is server HTTP requests.
type Horo ¶
type Horo struct { ErrorHandler ErrorHandlerFunc NotFound, MethodNotAllowed HandlerFunc Logger log.Logger RequestIDGenerator RequestIDGenerator // contains filtered or unexported fields }
Horo freamwork instance.
func (*Horo) DELETE ¶
func (h *Horo) DELETE(path string, hf HandlerFunc, mw ...MiddlewareFunc)
DELETE registers a new DELETE handler
func (*Horo) GET ¶
func (h *Horo) GET(path string, hf HandlerFunc, mw ...MiddlewareFunc)
GET registers a new GET handler
func (*Horo) HEAD ¶
func (h *Horo) HEAD(path string, hf HandlerFunc, mw ...MiddlewareFunc)
HEAD registers a new HEAD handler
func (*Horo) ListenAndServe ¶
ListenAndServe is Start HTTP Server
func (*Horo) OPTIONS ¶
func (h *Horo) OPTIONS(path string, hf HandlerFunc, mw ...MiddlewareFunc)
OPTIONS registers a new OPTIONS handler
func (*Horo) PATCH ¶
func (h *Horo) PATCH(path string, hf HandlerFunc, mw ...MiddlewareFunc)
PATCH registers a new PATCH handler
func (*Horo) POST ¶
func (h *Horo) POST(path string, hf HandlerFunc, mw ...MiddlewareFunc)
POST registers a new POST handler
func (*Horo) PUT ¶
func (h *Horo) PUT(path string, hf HandlerFunc, mw ...MiddlewareFunc)
PUT registers a new PUT handler
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc is process middleware.
type RequestIDGenerator ¶
RequestIDGenerator is generate requestID method interface.
var ( // DefaultRequestIDGenerator is application request id generator. DefaultRequestIDGenerator RequestIDGenerator = &reqGen{} )
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter is horo ResponseWriter
func Response ¶
func Response(c context.Context) (w *ResponseWriter)
Response returns ResponseWriter from context.
func (*ResponseWriter) CloseNotify ¶
func (r *ResponseWriter) CloseNotify() <-chan bool
CloseNotify implements http.CloseNotifier
func (*ResponseWriter) Committed ¶
func (r *ResponseWriter) Committed() bool
Committed is responsed flag.
func (*ResponseWriter) Header ¶
func (r *ResponseWriter) Header() http.Header
Header implements http.ResponseWriter
func (*ResponseWriter) Hijack ¶
func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements http.Hijacker
func (*ResponseWriter) Reset ¶
func (r *ResponseWriter) Reset(w http.ResponseWriter)
Reset cleanup struct
func (*ResponseWriter) Write ¶
func (r *ResponseWriter) Write(b []byte) (n int, err error)
Write implements http.ResponseWriter
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(code int)
WriteHeader implements http.ResponseWriter