Skip to content

bettercode-oss/gin-middleware-etag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov GitHub release (latest SemVer) GitHub go.mod Go version

HTTP ETag Cache Middleware

Gin middleware/handler to enable HTTP Etag support.

Usage

Start using it

Download and install it:

go get github.com/bettercode-oss/gin-middleware-etag

Import it in your code:

import "github.com/bettercode-oss/gin-middleware-etag"

Example

package main

import (
  "github.com/gin-gonic/gin"
  "github.com/bettercode-oss/gin-middleware-etag"
  "net/http"
)

func main() {
  r := gin.Default()
  r.GET("/products", etag.HttpEtagCache(120), getProducts)
  r.Run()
}

func getProducts(c *gin.Context) {
  products := []map[string]any{
    {
        "id":        1,
        "name":      "큰 잔",
        "listPrice": 1000,
    },
    {
        "id":        2,
        "name":      "작은 잔",
        "listPrice": 2000,
    },
  }

  c.JSON(http.StatusOK, products)
}

About

Gin middleware/handler to enable HTTP Etag support.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages