8000 GitHub - dpouris/goster at readme
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ goster Public

An API framework and micro-service helper in Go featuring dynamic routing, middleware support, and integrated logging

License

Notifications You must be signed in to change notification settings

dpouris/goster

 
 

Repository files navigation

Goster 🚀

GoDoc Go Report Card License Go version

Welcome to Goster, the lightweight and efficient web framework for Go! 🌟

Why Goster?

  • 🚀 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.

Installation

Install Goster using go get:

go get -u github.com/dpouris/goster

Quick Start

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")
}

Usage

  • 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"
     }

Examples

Check out these examples to get started quickly:

Contributing

I welcome contributions! Please see our Contributing Guide for more information.

License

Goster is licensed under the MIT License. See the LICENSE file for details.

About

An API framework and micro-service helper in Go featuring dynamic routing, middleware support, and integrated logging

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0