Welcome to Goster, the lightweight and efficient web framework for Go! 🌟
- 🚀 Fast and Lightweight: Build with simplicity in mind, Goster provides a minimalistic abstraction on top of the built-in http package.
- 📊 Intuitive API: Easy-to-use API that simplifies web development without sacrificing flexibility.
- 🛠 Extensible Middleware: Seamlessly add middleware to enhance your application's functionality.
- 🔍 Dynamic Routing: Effortlessly handle both static and dynamic routes.
- 🧪 Configurable Logging (TODO): Powerful and customizable logging to keep track of your application's activity.
Install Goster using go get
:
go get -u github.com/dpouris/goster
Create your first Goster server:
package main
import (
"github.com/dpouris/goster"
)
func main() {
g := goster.NewServer()
g.Get("/", func(ctx *goster.Ctx) error {
ctx.Text("Hello, Goster!")
return nil
})
g.ListenAndServe(":8080")
}
-
Create a new server:
g := Goster.NewServer()
-
Add a
GET
Route:g.Get("/path", func(ctx *Goster.Ctx) error { // Handler logic })
-
Add a
Dynamic Route
:g.Post("/path/:id", func(ctx *Goster.Ctx) error { // Handler logic })
-
Add
Global Middleware
:g.UseGlobal(func(ctx *Goster.Ctx) error { // middleware logic })
-
Add
Path specific Middleware
:g.Use("/path", func(ctx *Goster.Ctx) error { // middleware logic })
-
Logging:
By default Goster handles all incoming requests and Logs the info on the Logs field. On the example below, we craete a new instance of Goster server and supply
Goster.Logger
to the Log functions.import Goster "github.com/dpouris/goster/goster" func main() { g := Goster.NewServer() // Logs to stdout Goster.LogInfo("This is an info message", g.Logger) Goster.LogWarning("This is an warning message", g.Logger) Goster.LogError("This is an error message", g.Logger) }
// OUTPUT 2022/06/07 11:45:40 INFO - This is an info message 2022/06/07 11:45:40 WARN - This is an warning message 2022/06/07 11:45:40 ERROR - This is an error message
-
All logs:
You can access all the logs on the
Goster.Logs
field.g.Get("/logs", func(ctx *Goster.Ctx) error { log_map := make(map[int]any, len(g.Logs)) for i, v := range g.Logs { log_map[i] = v } r.JSON(log_map) return nil })
Sample Response
// Logs are stored in the Logs field of Goster instance { "0": "[GET] ON ROUTE /hey", "1": "[GET] ON ROUTE /logs" }
Check out these examples to get started quickly:
I welcome contributions! Please see our Contributing Guide for more information.
Goster is licensed under the MIT License. See the LICENSE file for details.