All Projects → vincentbin → goweb

vincentbin / goweb

Licence: Apache-2.0 license
A gin-like simple golang web framework.

Programming Languages

go
31211 projects - #10 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to goweb

Frappejs
Node + Electron + Vue based metadata web framework (inspired by Frappe)
Stars: ✭ 214 (+872.73%)
Mutual labels:  webframework
presley
Presley - A lightweight web framework for Windows
Stars: ✭ 26 (+18.18%)
Mutual labels:  webframework
fly
Lightweight Python Web framework
Stars: ✭ 17 (-22.73%)
Mutual labels:  webframework
GCMS
PHP FASTEST CMS with Ajax support
Stars: ✭ 19 (-13.64%)
Mutual labels:  webframework
tsukuyomi
Asynchronous Web framework for Rust
Stars: ✭ 81 (+268.18%)
Mutual labels:  webframework
sitefox
Node + cljs backend web framework
Stars: ✭ 180 (+718.18%)
Mutual labels:  webframework
Closp
Clojure template for web development (with SPA support)
Stars: ✭ 173 (+686.36%)
Mutual labels:  webframework
elton
High performance, simple Go web framework
Stars: ✭ 61 (+177.27%)
Mutual labels:  webframework
godzilla
a powerful go web framework
Stars: ✭ 22 (+0%)
Mutual labels:  webframework
sgo
A simple, light and fast Web framework written in Go.
Stars: ✭ 75 (+240.91%)
Mutual labels:  webframework
mango
mango is a powerful and simple golang web framework
Stars: ✭ 20 (-9.09%)
Mutual labels:  webframework
nim-servy
Servy is a fast, simple and lightweight micro web-framework for Nim
Stars: ✭ 30 (+36.36%)
Mutual labels:  webframework
flask-empty-api
AZAP Flask boilerplate for creating API's with flask.
Stars: ✭ 15 (-31.82%)
Mutual labels:  webframework
Golf
⛳️ The Golf web framework
Stars: ✭ 248 (+1027.27%)
Mutual labels:  webframework
waspy
WASP framework for Python
Stars: ✭ 43 (+95.45%)
Mutual labels:  webframework
Clog
CLOG - The Common Lisp Omnificent GUI
Stars: ✭ 181 (+722.73%)
Mutual labels:  webframework
firmeve
a out-of-the-box, full-featured go framework supporting http, http2, websocket, tcp, udp, rpc and microservice
Stars: ✭ 36 (+63.64%)
Mutual labels:  webframework
digwebs
A tiny Python web framework that power the web app
Stars: ✭ 16 (-27.27%)
Mutual labels:  webframework
faces
Jakarta Faces
Stars: ✭ 44 (+100%)
Mutual labels:  webframework
Teapot
Teapot micro web framework for Pharo Smalltalk
Stars: ✭ 86 (+290.91%)
Mutual labels:  webframework

webgo

A gin-like simple golang web framework.

一个基于golang的简易web框架,实现了静态、动态路由映射,分组映射,静态文件传输,模板渲染。

Getting Start

支持动态、静态路由,分组路由配置,以及静态文件获取,模板渲染页面。


静态路由:

func main() {
    s := server.InitServer()
    s.Get("/level1/level2", func(c *server.Context) {
		  c.JSON(http.StatusOK, server.Content{
        "username": "yanyibin",
        "password": "yyb",
      })
    })
    s.Run("localhost:9999")
}

动态路由:

可由Context中PathParams中获得动态路由名
利用trie树进行实现

func main() {
    s := server.InitServer()
    s.Get("/level1/:v1", func(c *server.Context) {
      c.JSON(http.StatusOK, server.Content{
        "pathParam": c.PathParams["v1"]
        "username": "yanyibin",
        "password": "yyb",
      })
    })
    s.Run("localhost:9999")
}

分组路由:

func main() {
    s := server.InitServer()
    g := s.SetGroup("/group1")
    {
        g.Get("/level1/:v1", func(c *server.Context) {
          c.JSON(http.StatusOK, server.Content{
            "pathParam": c.PathParams["v1"]
            "username": "yanyibin",
            "password": "yyb",
          })
        })
        
        g.Get("/level2/:v2", func(c *server.Context) {
          c.JSON(http.StatusOK, server.Content{
            "pathParam": c.PathParams["v2"]
            "username": "yanyibin",
            "password": "yyb",
          })
        })
    }
    s.Run("localhost:9999")
}

静态文件访问、模板渲染:

通过localhost:9999/student 即可获取test.tmpl对应页面。

type student struct {
    Name string
    Age  int
}

func main() {
    s := server.InitServer()
    s.LoadTemplate("test/templates/*")
    s.StaticResource("/static/css", "test/static")
    
    s1 := &student{Name: "yanyibin", Age: 23}
    s2 := &student{Name: "ty", Age: 23}
    
    s.Get("/student", func(c *server.Context) {
      c.HTML(http.StatusOK, "test.tmpl", server.Content{
        "title":    "yanyibin",
        "students": [2]*student{s1, s2},
      })
    })
    s.Run("localhost:9999")
}

目录结构

目录结构描述

.
├── README.md                   // readme
├── server                      
│   ├── context.go              // 请求上下文
│   ├── group.go                // 服务url前缀分组
│   ├── router.go               // 请求路由
│   ├── server.go               // 服务相关
|
├── util
|   |── string.go               // 字符串处理工具
|   |── trie.go                 // 实现动态路由 trie树
|
├── test                        // 静态文件测试用包
|   |── static                  // js & css
|   |── templates               // tmpl模板
|
├── test.go                     // 测试启动类
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].