gomvc

package module
v0.0.0-...-8477de9 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2015 License: GPL-2.0 Imports: 8 Imported by: 0

README

gomvc

gomvc is a simple Web Mvc libs for go

##Installation

installation

go get github.com/nexigolabs/gomvc

how to use main

package main

import (
	"github.com/nexigolabs/gomvc"
	"myapps/controllers"
)

func init() {
	gomvc.SetConfig("port", "9090")
}

func main() {
	gomvc.RouteFolder("/", "www")
	gomvc.Route("layout", &controllers.LayoutController{})
	gomvc.Route("process", &controllers.ProcessController{})

	gomvc.Run()
}

how to use controllers

package controllers

import (
	"github.com/nexigolabs/gomvc"
	"net/http"
)

type LayoutController struct {
	gomvc.Controller
}

func (c *LayoutController) Text(rw http.ResponseWriter, req *http.Request) {
	c.ServeText("<h1>Demo</h1> serve <b>text</b>")
}

func (c *LayoutController) Html(rw http.ResponseWriter, req *http.Request) {
	c.ServeHtml("<h1>Demo</h1> serve <b>html</b>")
}

func (c *LayoutController) View(rw http.ResponseWriter, req *http.Request) {
	c.ServeView("view.html", nil)
}

func (c *LayoutController) Json(rw http.ResponseWriter, req *http.Request) {
	data := make(map[string]interface{})
	data["firstName"] = "Peter"
	data["lastName"] = "Parker"
	data["alias"] = "Spiderman"
	c.ServeJson(data)
}

func (c *LayoutController) Template(rw http.ResponseWriter, req *http.Request) {
	data := make(map[string]interface{})
	data["Title"] = "Nexigo"
	c.ServeTpl([]string{"views/app/home.html", "views/header.tpl", "views/footer.tpl"}, data)
}

func (c *LayoutController) Index(rw http.ResponseWriter, req *http.Request) {
	c.Redirect("/login")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HttpContext = ContextHandler{}

	Session *sessions.CookieStore = nil
)

Functions

func GetConfig

func GetConfig(name string) interface{}

func GetFormValue

func GetFormValue(r *http.Request) map[string]interface{}

func GetSession

func GetSession(req *http.Request, sessionName string) (*sessions.Session, error)

func Route

func Route(path string, ctl interface{})

func RouteFolder

func RouteFolder(path string, folder string)

func Run

func Run()

func SetConfig

func SetConfig(name string, value interface{})

func SetSession

func SetSession(secret string) *sessions.CookieStore

func Socket

func Socket(path string, ctl interface{}, checkOrigin bool)

func Test

func Test()

func Text

func Text()

Types

type ContextHandler

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

type Controller

type Controller struct {
	MsgType   string
	Html      string
	Text      string
	Templates []string
	Data      interface{}
}

func (*Controller) New

func (c *Controller) New(mtype string)

func (*Controller) Redirect

func (c *Controller) Redirect(url string)

func (*Controller) RunAction

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

func (*Controller) ServeHtml

func (c *Controller) ServeHtml(html string)

func (*Controller) ServeJson

func (c *Controller) ServeJson(data interface{})

func (*Controller) ServeText

func (c *Controller) ServeText(text string)

func (*Controller) ServeTpl

func (c *Controller) ServeTpl(tmpls []string, data interface{})

func (*Controller) ServeView

func (c *Controller) ServeView(view string, data interface{})

type RouteHandler

type RouteHandler struct {
	Path        string
	IController interface{}
}

Jump to

Keyboard shortcuts

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