Go語言web框架:Seago

jopen 10年前發布 | 20K 次閱讀 Seago Google Go/Golang開發

Seago是golang實現的簡單的web框架,router包來自web.go和martini

功能

  • 支持RESTful

  • 支持Session

  • 支持Cache

  • 支持Middleware

package main

import (
    "fmt"
    "github.com/seago/seago"
    "github.com/seago/seago/context"
    . "github.com/seago/seago/middleware"
    "io"
    "os"
    "strconv"
)

func main() {
    DefaultMiddleware.Add("test", "test middleware")
    app := seago.NewSeago(":8080")

    //http://localhost:8080/test/Miller
    app.Get("/test/:test_get", func(ctx *context.Context, test string) string {
        i := ctx.GetParam("id_get").Int()
        return "hello " + test + " " + strconv.Itoa(i) + " " + DefaultMiddleware.Get("test").(string)
    })
    app.Post("/test", func(ctx *context.Context) string {
        test := ctx.GetParam("test_post").String()
        i := ctx.GetParam("id_post").Int()
        file := ctx.File["file"]
        f, err := file.Open()
        if err != nil {
            fmt.Println(err)
        }
        defer f.Close()
        fi, err := os.Create(file.Filename)
        if err != nil {
            fmt.Println(err)
        }
        _, err = io.Copy(fi, f)
        if err != nil {
            fmt.Println(err)
        }
        defer fi.Close()

        return "hello " + test + " " + strconv.Itoa(i)
    })
    app.Get("/", func() string {
        return `<html>
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <title>test file upload</title>
                    </head>
                    <body>
                        <form action="http://localhost:8080/test" method="post" enctype="multipart/form-data">
                            test:<input type="text" name="test_post" value="" /><br />
                            id:<input type="text" name="id_post" value="" /><br />
                            <input type="file" name="file" /><br />
                            <input type="submit" name="submit" value="upload" />
                        </form>
                    </body>
                </html>`
    })
    app.Profile()
    app.Server.SetMaxMemory(200 << 20)
    app.Run()

}

項目主頁:http://www.baiduhome.net/lib/view/home/1399591842556

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!