Go的MVC框架 go-fastweb

BSD
Google Go
跨平台
2012-04-09
红薯

go-fastweb 是 Go 语言实现的一个 MVC 框架。

使用案例:

package main

import (
       
"fastweb"
       
"os"
)

type
Products struct {
        fastweb
.Controller
       
Name string
       
Brand string
       
Features []string
       
Specifications []string
       
Image string
}

func
(p *Products) View(id string) os.Error {
       
if id == "ah64" {
                p
.Name = "RC Apache AH64 4-Channel Electric Helicoper"
                p
.Brand = "Colco"
                p
.Features = []string{
                       
"4 channel radio control duel propeller system",
                       
"Full movement controll: forward, backward, left, right, up and down",
                       
"Replica design",
                       
"Revolutionary co-axial rotor technology",
               
}
                p
.Specifications = []string{
                       
"Dimensions: L 16 Inches X W 5.5 Inches x H 6.5 Inches",
                       
"Battery Duration: 10 min",
                       
"Range: 120 Feet",
               
}
                p
.Image = "/img/ah64.jpg"
       
}
       
return nil
}

func main
() {
        a
:= fastweb.NewApplication()
        a
.RegisterController(&Products{})
        a
.Run(":12345")
}

and the template of the page body (example/views/products/view.tpl):

{.section Name}
Name: {Name}<br/>
Manufacturer: {Brand}<br/>
{.section Image}
<img src="{Image}"><br/>
{.end}
{.section Features}
Features:<br/>
<ul>
{.repeated section @}
<li>{@}</li>
{.end}
</ul>
{.end}
{.section specifications}
Specifications:<br/
>
<ul>
{.repeated section @}
<li>{@}</li>
{.end}
</ul>
{.end}
{.or}
No product was found.
{.end}

Sample Lighttpd Config

$HTTP["host"] =~ "" {
        server
.document-root = "/home/ivan/go-fastweb/example/htdocs/"
        server
.error-handler-404 = "/dispatch.fcgi"
        fastcgi
.server = (
               
".fcgi" => ( "localhost" => (
                       
"host" => "127.0.0.1",
                       
"port" => 12345,
                       
"check-local" => "disable",
                 
)))
}

Sample Apache Config

<VirtualHost *:80>
        ServerName      fastweb
        DocumentRoot    /home/ivan/go-fastweb/example/htdocs/

        ErrorLog /var/log/apache2/fastweb.error.log
        LogLevel warn
        CustomLog /var/log/apache2/fastweb.access.log combined
        ServerSignature On

        AddHandler fastcgi-script .fcgi
        FastCgiExternalServer /home/ivan/go-fastweb/example/htdocs/dispatch.fcgi -host 127.0.0.1:12345
        RewriteEngine On
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /dispatch.fcgi [QSA,L]
</VirtualHost>
加载中

评论(0)

暂无评论

暂无资讯

暂无问答

关于CloudXNS注册邮箱为网易的处理办法

近日网易邮箱被曝出现邮箱数据泄漏。泄漏内容涉及邮箱帐号、密码和用户密保等重要信息。CloudXNS提醒各位用户在CloudXNS上用网易邮箱注册的朋友尽快修改邮箱密码以及密保信息等。同时,Cloud...

2015/11/04 16:43
17
0
Go 语言项目

Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org gowalker gosearch Sourcegraph Contributing To edit this page you must be a c...

2014/01/03 21:49
749
0

没有更多内容

加载失败,请刷新页面

没有更多内容

返回顶部
顶部