Skip to content

xgdapg/wtk

Repository files navigation

WTK

WTK is a simple web toolkit to build webapp easily in Go.

Requirement

Go 1.1+ or tip

Installation

go get github.com/xgdapg/wtk

GoDoc

http://godoc.org/github.com/xgdapg/wtk

WIKI

https://github.com/xgdapg/wtk/wiki

Example

package main

import (
	"github.com/xgdapg/wtk"
	"strconv"
)

func main() {
	wtk.AddRoute("/", &IndexHandler{})
	// Both /post/id123 and /post/id123-2 will be routed to the same Handler.
	wtk.AddRoute("/post/{id}", &PageHandler{})
	wtk.AddRoute("/post/{id}-{page([0-9]+)}", &PageHandler{})
	wtk.Run()
}

type IndexHandler struct {
	wtk.Handler
}

func (this *IndexHandler) Get() {
	this.Context.WriteString("Hello, index page")
}

type PageHandler struct {
	wtk.Handler
}

func (this *PageHandler) Get() {
	id := this.Context.GetPathVar("id")
	strPage := this.Context.GetPathVar("page")
	page := 0
	if strPage != "" {
		page, _ = strconv.Atoi(strPage)
	}
	this.Template.SetVar("Title", "The post title")
	this.Template.SetVar("Content", "The post content")
	this.Template.SetVar("Id", id)
	this.Template.SetVar("Page", page)
	this.Template.SetTemplateFile("post.tpl")
}

About

A simple web toolkit to build webapp easily in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages