neo

package module
v0.0.0-...-7ad7368 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2015 License: MIT Imports: 14 Imported by: 0

README

Neo

Build Status GoDoc

Go Web Framework

Installation

# framework
go get github.com/ivpusic/neo

# CLI tool
go get github.com/ivpusic/neo/cmd/neo

Documentation

Project Site

API Documentation

Example

Create Neo application

neo new myapp
cd myapp
package main

import (
    "github.com/ivpusic/neo"
)

func main() {
    app := neo.App()

    app.Get("/", func(ctx *neo.Ctx) {
        ctx.Res.Text("I am Neo Programmer", 200)
    })

    app.Start()
}

Run it!

neo run main.go

License

MIT

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

View Source
const (
	GET     = "GET"
	POST    = "POST"
	PUT     = "PUT"
	DELETE  = "DELETE"
	OPTIONS = "OPTIONS"
	HEAD    = "HEAD"
)

supported HTTP methods

Variables

This section is empty.

Functions

func Assert

func Assert(condition bool, status int, message []byte)

Asserting some condition. If assertion fails, code bellow assert won't execute, and Neo will return to client provided “status“ and “message“.

func AssertNil

func AssertNil(obj interface{}, status int, message []byte)

Same as assert, but instead of passing some boolean condition as first argument, here we are passing object, and checking if object is nil.

func AssertNotNil

func AssertNotNil(obj interface{}, status int, message []byte)

Same as assert, but instead of passing some boolean condition as first argument, here we are passing object, and checking if object is not nil.

Types

type AppModeSettings

type AppModeSettings struct {
	Addr string
}

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.

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) SetConfigFile

func (a *Application) SetConfigFile(confFile string)

SetConfigFile lets you optionally set custom config file path.

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 ApplicationSettings

type ApplicationSettings struct {
	Addr   string
	Logger LoggerSettings
}

type Conf

type Conf struct {
	Hotreload HotReload
	App       ApplicationSettings
	Neo       NeoSettings
}

func (*Conf) Parse

func (c *Conf) Parse(path string)

Will try to parse TOML configuration file.

type Cookie map[string]*http.Cookie

Map of cookies which will be sent to client.

func (Cookie) Del

func (cookies Cookie) Del(key string)

func (Cookie) Get

func (cookies Cookie) Get(key string) *http.Cookie

func (Cookie) Set

func (cookies Cookie) Set(key string, value string)

func (Cookie) SetCustom

func (cookies Cookie) SetCustom(cookie *http.Cookie)

Set *http.Cookie instance to Response

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
}

Representing context for this request.

type CtxData

type CtxData map[string]interface{}

Map which will hold your Request contextual data.

func (CtxData) Del

func (r CtxData) Del(key string)

Delete contextual data on key

func (CtxData) Get

func (r CtxData) Get(key string) interface{}

Get context data on key

func (CtxData) Set

func (r CtxData) Set(key string, value interface{})

Add new contextual data on key with provided value

type HotReload

type HotReload struct {
	Command string
	Watch   []string
	Ignore  []string
}

type LoggerSettings

type LoggerSettings struct {
	Name  string
	Level string
}

type NeoAssertError

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

Type which will be passed as argument of “panic“ if Neo assertion fails.

type NeoSettings

type NeoSettings struct {
	Logger LoggerSettings
}

type Next

type Next func()

type Region

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

func (Region) Delete

func (m Region) Delete(path string, fn handler) *Route

Registering route handler for “DELETE“ request on provided path

func (Region) Get

func (m Region) Get(path string, fn handler) *Route

Registering route handler for “GET“ request on provided path

func (Region) Head

func (m Region) Head(path string, fn handler) *Route

Registering route handler for “HEAD“ request on provided path

func (Region) Options

func (m Region) Options(path string, fn handler) *Route

Registering route handler for “OPTIONS“ request on provided path

func (Region) Post

func (m Region) Post(path string, fn handler) *Route

Registering route handler for “POST“ request on provided path

func (Region) Put

func (m Region) Put(path string, fn handler) *Route

Registering route handler for “PUT“ request on provided path

func (Region) Use

func (m Region) Use(fn middleware)

Adding new middleware into chain of middlewares.

type Request

type Request struct {
	*http.Request
	Params UrlParam
}

Wrapped http.Request. It contains utility methods for dealing with content of incomming http.Request instance.

func (*Request) JsonBody

func (r *Request) JsonBody(instance interface{}) error

Parse incomming Body as JSON

type Response

type Response struct {
	Status int
	Writer http.ResponseWriter

	Cookie Cookie

	Header http.Header
	// contains filtered or unexported fields
}

Server response representation.

func (*Response) File

func (r *Response) File(path string)

Find file, and send it to client.

func (*Response) Json

func (r *Response) Json(obj interface{}, status int)

Will produce JSON string representation of passed object, and send it to client

func (*Response) Raw

func (r *Response) Raw(data []byte, status int)

Send Raw data to client.

func (*Response) Text

func (r *Response) Text(text string, status int)

Will send provided Text to client.

func (*Response) Tpl

func (r *Response) Tpl(name string, data interface{})

Will look for template, render it, and send rendered HTML to client. Second argument is data which will be passed to client.

func (*Response) Xml

func (r *Response) Xml(obj interface{}, status int)

Will produce XML string representation of passed object, and send it to client

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 Static

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

func (*Static) Serve

func (s *Static) Serve(url string, path string)

Serving static files from some directory. If provided url is for example “/assets“, then all requests starting with “/assets“ will be served from directory provided by “path“ parameter.

type UrlParam

type UrlParam map[string]string

Representing named url parameters. For example if we have url like: “/some/:name/other/:lastname“, then named parameters are “name“ and “lastname“.

func (UrlParam) Exist

func (u UrlParam) Exist(key string) bool

func (UrlParam) Get

func (u UrlParam) Get(key string) string

Directories

Path Synopsis
cmd
neo
middlewares
logger
Middleware for logging all requests and respones to Neo server.
Middleware for logging all requests and respones to Neo server.

Jump to

Keyboard shortcuts

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