Documentation
¶
Overview ¶
Go Web Framework.
Hello world example:
package main import ( "github.com/ivpusic/neo" ) func main() { app := neo.App() app.Get("/", func(this *neo.Ctx) { this.Res.Text("I am Neo Programmer", 200) }) app.Start() }
Here you can find Neo API documentation. For tutorials visit project website. http://178.62.122.135/
Index ¶
- Constants
- type Application
- type ApplicationConf
- type Conf
- type Cookie
- type Ctx
- type CtxData
- type HotReloadConf
- type LoggerConf
- type Middleware
- type NeoConf
- type Next
- type Region
- func (m Region) Delete(path string, fn handler) *Route
- func (m Region) Get(path string, fn handler) *Route
- func (m Region) Head(path string, fn handler) *Route
- func (m Region) Options(path string, fn handler) *Route
- func (m Region) Post(path string, fn handler) *Route
- func (m Region) Put(path string, fn handler) *Route
- func (m Region) Use(fn Middleware)
- type Request
- type Response
- func (r *Response) File(path string) error
- func (r *Response) Header() http.Header
- func (r *Response) Json(obj interface{}) error
- func (r *Response) Raw(data []byte) error
- func (r *Response) Redirect(url string) error
- func (r *Response) Text(text string) error
- func (r *Response) Tpl(name string, data interface{}) error
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteHeader(s int)
- func (r *Response) Writer() http.ResponseWriter
- func (r *Response) Xml(obj interface{}) error
- type Route
- type Session
- type Static
- type UrlParam
Constants ¶
const ( BYTE = 1.0 KILOBYTE = 1024 * BYTE MEGABYTE = 1024 * KILOBYTE GIGABYTE = 1024 * MEGABYTE TERABYTE = 1024 * GIGABYTE )
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" OPTIONS = "OPTIONS" HEAD = "HEAD" )
supported HTTP methods
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct { // Event emmiter/receiver ebus.EBus // Application Configuration parameters Conf *Conf // Application logger instance Logger *golog.Logger // contains filtered or unexported fields }
Representing Neo application instance
func App ¶
func App() *Application
Getting Neo Application instance. This is singleton function. First time when we call this method function will try to parse configuration for Neo application. It will look for configuration file provided by “--config“ CLI argument (if exist).
func (*Application) Region ¶
func (a *Application) Region() *Region
Making new region instance. You can create multiple regions.
func (*Application) Serve ¶
func (a *Application) Serve(url string, path string)
Defining paths for serving static files. For example if we say: a.Serve("/some", "./mypath") then if we require “/some/js/file.js“, Neo will look for file at “./mypath/js/file.js“.
func (*Application) ServeHTTP ¶
func (a *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
Handler interface “ServeHTTP“ implementation. Method will accept all incomming HTTP requests, and pass requests to appropriate handlers if they are defined.
func (*Application) Start ¶
func (a *Application) Start()
Starting application instance. This will run application on port defined by configuration.
func (*Application) Templates ¶
func (a *Application) Templates(templates ...string)
If you are planning to return templates from Neo route handler, then you have to compile them. This method will accept list of paths/files and compile them. You can use also paths with wildcards (example: /some/path/*).
type ApplicationConf ¶
type Conf ¶
type Conf struct { Hotreload HotReloadConf App ApplicationConf Neo NeoConf }
Neo Application configuration
type Ctx ¶
type Ctx struct { ebus.EBus // Wrapped http.Request object. Req *Request // Object with utility methods for writing responses to http.ResponseWriter Res *Response // Context data map Data CtxData // general purpose session instance Session Session // list of errors happened in current http request Errors []error }
Representing context for this request.
type CtxData ¶
type CtxData map[string]interface{}
Map which will hold your Request contextual data.
type HotReloadConf ¶
type LoggerConf ¶
type Middleware ¶
Representing middleware handler. It accepts Neo Context and Next function for calling next middleware in chain.
type NeoConf ¶
type NeoConf struct {
Logger LoggerConf
}
type Region ¶
type Region struct {
// contains filtered or unexported fields
}
func (Region) Use ¶
func (m Region) Use(fn Middleware)
Adding new middleware into chain of middlewares.
type Request ¶
Wrapped http.Request. It contains utility methods for dealing with content of incomming http.Request instance.
func (*Request) StringBody ¶
type Response ¶
Server response representation.
func (*Response) Json ¶
Will produce JSON string representation of passed object, and send it to client
func (*Response) Tpl ¶
Will look for template, render it, and send rendered HTML to client. Second argument is data which will be passed to client.
func (*Response) WriteHeader ¶
Write Header. Implements ResponseWriter.WriterHeader.
func (*Response) Writer ¶
func (r *Response) Writer() http.ResponseWriter
Get http.ResponseWriter directly
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (Route) Use ¶
func (m Route) Use(fn Middleware)
Adding new middleware into chain of middlewares.
type Session ¶
type Session struct { // is user authenticated? Authenticated bool // data about logged user User interface{} // other data Data interface{} }
Purpose of this struct is to be used by authentication and authorization middlewares. Saving session is common in many web applications, and this struct is trying to provide type-safe version of it.