Gee is a minimalistic and flexible web framework for the Go programming language, designed with inspiration from Gin. With a focus on simplicity and extensibility, Gee empowers developers to build robust web applications effortlessly. This framework incorporates essential features for routing, middleware support, HTML template rendering, and error handling.
Gee/
│
├── geeweb/
│ ├── gee.go
│ ├── gee_test.go
│ ├── context.go
│ ├── router.go
│ ├── router_test.go
│ ├── trie.go
│ ├── logger.go
│ ├── recovery.go
│ └── go.mod
├── static/
│ ├── css
│ │ └── mitsui.css
│ └── file1.txt
├── templates/
│ ├── arr.tmpl
│ ├── css.tmpl
│ └── custom_func.tmpl
├── main.go
├── go.mod
└── README
To integrate Gee into your Go project, follow these steps:
-
Install Gee:
go get -u github.com/Mitsui515/Gee
-
Import Gee in your Go code:
import "github.com/Mitsui515/Gee/geeweb"
-
Create a Gee instance:
r := geeweb.New()
-
Define routes using various HTTP methods:
r.GET("/", func(c *geeweb.Context) { c.HTML(http.StatusOK, "<h1>Hello, Gee!</h1>") }) r.POST("/submit", func(c *geeweb.Context) { // Handle POST request })
-
Run the web server:
r.Run(":8080")
Gee provides a straightforward routing mechanism, allowing developers to define static and dynamic routes effortlessly. Dynamic routing supports parameter matching (:name
) and wildcard matching (*filepath
), offering flexibility for various use cases.
The Context
struct encapsulates HTTP request and response information, simplifying access to parameters, query data, and response rendering. Context instances enable the building of powerful and extensible web applications.
Gee supports middleware to enhance functionality and introduce additional features. Middleware can be easily added and customized, allowing developers to apply various layers of processing to incoming requests.
Route grouping allows for organized and controlled route management. Developers can group routes with similar characteristics, making it easier to apply middleware, manage nested groups, and improve overall code organization.
Gee enables the serving of static files, such as JavaScript, CSS, and HTML resources. This feature simplifies the handling of client-side assets, enhancing the overall user experience.
The framework includes built-in support for rendering HTML templates using the html/template
package. Developers can leverage this feature to generate dynamic and data-driven HTML content.
Gee implements a robust error handling mechanism to prevent server crashes. The Recovery
middleware catches and logs panics, ensuring the stability and reliability of web applications.
r.GET("/", func(c *geeweb.Context) {
c.HTML(http.StatusOK, "<h1>Hello, Gee!</h1>")
})
r.GET("/hello/:name", func(c *geeweb.Context) {
name := c.Param("name")
c.String(http.StatusOK, "Hello, %s!", name)
})
// Logger middleware
r.Use(geeweb.Logger())
// Recovery middleware
r.Use(geeweb.Recovery())
Serve static files from the "/static" directory:
r.Static("/static", "/usr/web")
Render HTML templates:
r.LoadHTMLGlob("templates/*")
r.GET("/render", func(c *geeweb.Context) {
c.HTML(http.StatusOK, "arr.tmpl", geeweb.H{
"title": "Gee",
"arr": [3]int{1, 2, 3},
})
})