Go语言web框架:Seago

jopen 10年前

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.open-open.com/lib/view/home/1399591842556