The kwiscale Go Framework
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmd/kwiscale Move to "cmd" to respect standards May 5, 2016
.gitignore Websocket enhancement, route check and fixes Jul 25, 2015
LICENSE Change date Apr 30, 2016
README.md Change doc to use kwiscale command May 5, 2016
app.go
app_test.go Now, we can use HTTP Method with parameter Nov 1, 2015
base.go Fixup go convention Nov 12, 2015
conf.go Disabled DB, fixup static handler problems Oct 18, 2015
deprecated.go Bad function name, use PostValue() no PostVar() Feb 18, 2016
doc.go Documentation Nov 1, 2015
errors.go Fixup go convention Nov 12, 2015
handlerproduction.go Fixup go convention Nov 12, 2015
handlers.go Fix convention, deprecate GlobalCtx Nov 12, 2015
sessions.go Fixup go convention Nov 12, 2015
statichandler.go Fix prefix problem that made a 404 error Nov 11, 2015
template.go Adapt funcmap Jun 10, 2016
template_test.go Notify in test that an error is expected Nov 1, 2015
utils.go Fixup go convention Nov 12, 2015
wshandler.go Fixup go convention Nov 12, 2015

README.md

kwiscale

Join the chat at https://gitter.im/kwiscale/framework Build Status Coverage Status Documentation Status GoDoc

Web Middleware for Golang

At this time, Kwiscale is at the very begining of developpement. But you can test and give'em some pull-request to improve it.

Features

  • Implement your handlers as structs with HTTP Verbs as method
  • Plugin system for template engines, session engines and ORM
  • Use gorilla to manipulate routes and mux
  • Handler spawned with concurrency

How to use

Install with "go get" command:

go get gopkg.in/kwiscale/framework.v1
go get gopkg.in/kwiscale/framework.v1/cmd/kwiscale

Create a project:

kwiscale new app myapp
cd $GOPATH/myapp

Create a handler kwiscale new handler index / homepage

Open generated handlers/index.go and append "Get" method:

package handlers

import (
	"gopkg.in/kwiscale/framework.v1"
)


func init(){
	kwiscale.Register(&IndexHandler{})
}

type IndexHandler struct { kwiscale.RequestHandler }

func (handler *IndexHandler) Get(){
    handler.WriteString("Hello you !")
}

And run the app !:

go run *.go

Now, go to http://127.0.0.1:8000 - you should see "Hello You!". If not, check "kwiscale.yml" file if port is "8000", check error log, and so on.

If really there is a problem, please submit an issue.

Basic Templates

Kwiscale provides a "basic" template engine that use http/template. Kwiscale only add a "very basic template override system".

If you plan to have a complete override system, please use http://gopkg.in/kwiscale/template-pongo2.v1 that implements pango2 template.

See the following example.

Append templates directory:

mkdir templates

Then create templates/main.html:

<!DOCTYPE html>
<html>
    <head>
        <title>{{ if .title }}{{.title}}{{ else }} Default title {{ end }}</title>
    </head>
    <body>
        {{/* Remember to use "." as context */}}
        {{ template "CONTENT" . }}
    </body>
</html>

Now create templates/home directory:

mkdir templates/home

Create templates/home/welcome.html:

{{/* override "main.html" */}}

{{ define "CONTENT" }}
    This the welcome message {{ .msg }}
{{ end }}

This template overrides "main.html" (in ./templates/ directory) and append "CONTENT" template definition. So, the "CONTENT" block will appear at template "CONTENT" in "main.html". That's all.

In handlers/index.go you may now ask for template rendering:

func (h *IndexHandler) Get() {
    h.Render("home/welcome.html", map[string]string{
        "title" : "Welcome !!!",
        "msg"   : "Hello you",
    })
}

You can override template directory using App configuration passed to the constructor:

app := kwiscale.NewApp(&kswiscale.Config{
    TemplateDir: "./my-template-dir",
})

TODO

Features in progress:

  • Database ORM interface
  • Custom Error handler