Brijesh's Git Server — toolkit @ main

my attempt at building my own web framework so I feel more confident when using chi

07f7705d
re-releasing pacakge
Brijesh ops@brijesh.dev
Thu, 29 Aug 2024 17:44:42 +0530

Toolkit

Toolkit is a Go library providing utilities for API development.

Table of Contents

Installation

To install Toolkit, use the following command:

go get brijesh.dev/toolkit

Usage

Here’s a quick example of how to use Toolkit:

package main

import (
 "net/http"
 "time"

 "brijesh.dev/toolkit/middleware"
 "brijesh.dev/toolkit/router"
)

type response struct {
 Message   string      `json:"message"`
 Error     error       `json:"error"`
 Data      interface{} `json:"data"`
 RequestID string      `json:"request_id"`
}

func main() {
 r := router.NewRouter()

 r.Use(middleware.Logger)
 r.Use(middleware.RequestIDMiddleware)
 r.Use(middleware.RateLimit(2, time.Second))

 r.GET("/health", healthCheckHandler)

 http.ListenAndServe(":8080", r)
}

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
 response := response{
  Message:   "Okay",
  Error:     nil,
  Data:      nil,
  RequestID: middleware.GetRequestID(r),
 }
 router.SendResponse(w, http.StatusOK, response)
}

Features

clone
git clone https://brijesh.dev/toolkit.git