souin

package module
v0.0.0-...-d399288 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 4 Imported by: 0

README

Go-zero middleware: Souin

This is a distributed HTTP cache module for Go-zero based on Souin cache.

Features

Example

There is the example about the Souin initialization.

import (
	"net/http"

	cache "github.com/darkweak/souin/plugins/go-zero"
	// ...
)

func main(){

    // ...
	httpcache := cache.NewHTTPCache(cache.DevDefaultConfiguration)
	server.Use(httpcache.Handle)
    // ...

}

With that your application will be able to cache the responses if possible and returns at least the Cache-Status HTTP header with the different directives mentionned in the RFC specification.
You have to pass a Go-zero Configuration structure into the NewHTTPCache method (you can use the DefaultConfiguration variable to have a built-in production ready configuration).
See the full detailled configuration names here.

Other resources

You can find an example for a docker-compose stack inside the examples folder.
See the Souin configuration for the full configuration, and its associated development go-zero middleware

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConfiguration = middleware.BaseConfiguration{
		DefaultCache: &configurationtypes.DefaultCache{
			TTL: configurationtypes.Duration{
				Duration: 10 * time.Second,
			},
		},
		LogLevel: "info",
	}
	DevDefaultConfiguration = middleware.BaseConfiguration{
		API: configurationtypes.API{
			BasePath: "/souin-api",
			Prometheus: configurationtypes.APIEndpoint{
				Enable: true,
			},
			Souin: configurationtypes.APIEndpoint{
				Enable: true,
			},
		},
		DefaultCache: &configurationtypes.DefaultCache{
			Regex: configurationtypes.Regex{
				Exclude: "/excluded",
			},
			TTL: configurationtypes.Duration{
				Duration: 5 * time.Second,
			},
		},
		LogLevel: "debug",
	}
)

Functions

This section is empty.

Types

type SouinGozeroMiddleware

type SouinGozeroMiddleware struct {
	*middleware.SouinBaseHandler
}

SouinGoZeroMiddleware declaration.

func (*SouinGozeroMiddleware) Handle

Directories

Path Synopsis
internal/handler
Code generated by goctl.
Code generated by goctl.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL