beego

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: 10 Imported by: 0

README

Beego filter: Souin

This is a distributed HTTP cache module for Beego based on Souin cache.

Features

Example

There is the example about the Souin initialization.

import (
	"net/http"

	httpcache "github.com/darkweak/souin/plugins/beego"
)

func main(){

    // ...
	web.InsertFilterChain("/*", httpcache.NewHTTPCacheFilter())
    // ...

}

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.
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 beego filter

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

func NewHTTPCacheFilter

func NewHTTPCacheFilter() web.FilterChain

Types

type CustomWriter

type CustomWriter struct {
	Buf     *bytes.Buffer
	Rw      http.ResponseWriter
	Req     *http.Request
	Headers http.Header
	// contains filtered or unexported fields
}

CustomWriter handles the response and provide the way to cache the value

func (*CustomWriter) Header

func (r *CustomWriter) Header() http.Header

Header will write the response headers

func (*CustomWriter) Send

func (r *CustomWriter) Send() (int, error)

Send delays the response to handle Cache-Status

func (*CustomWriter) Write

func (r *CustomWriter) Write(b []byte) (int, error)

Write will write the response body

func (*CustomWriter) WriteHeader

func (r *CustomWriter) WriteHeader(code int)

WriteHeader will write the response headers

type SouinBeegoMiddleware

type SouinBeegoMiddleware struct {
	*middleware.SouinBaseHandler
}

SouinBeegoMiddleware declaration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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