cookie

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(secret []byte) func(http.Handler) http.Handler

Middleware creates a CookieManager with a secret key and returns a middleware function that stores the manager in the request context. Middleware는 비밀키(secret)를 이용하여 CookieManager를 생성하고, 이를 요청 컨텍스트에 저장하는 미들웨어 함수를 반환합니다.

Types

type CookieManager

type CookieManager struct {
	// SecretKey is used for HMAC signing.
	// SecretKey는 HMAC 서명에 사용할 비밀키입니다.
	SecretKey []byte
}

CookieManager holds the secret key for signing and provides cookie manipulation functions. CookieManager는 쿠키 조작 기능과 보안 서명을 위한 비밀키를 보유합니다.

func GetCookieManager

func GetCookieManager(ctx context.Context) *CookieManager

GetCookieManager retrieves the CookieManager instance from the current request's context. It panics if the CookieManager is not found, which helps to ensure that the middleware is correctly configured. GetCookieManager 함수는 현재 요청의 컨텍스트에서 CookieManager 인스턴스를 추출합니다. 만약 인스턴스를 찾을 수 없다면 패닉을 발생시켜, 미들웨어가 올바르게 설정되었음을 보장하는 데 도움을 줍니다.

func (*CookieManager) DelCookie

func (cm *CookieManager) DelCookie(w http.ResponseWriter, name string)

DelCookie deletes a cookie by name by setting its expiration time to the past. DelCookie는 지정한 이름(name)의 쿠키를 삭제하기 위해, 만료 시간을 과거로 설정하여 응답에 등록합니다.

func (*CookieManager) ReadCookie

func (cm *CookieManager) ReadCookie(r *http.Request, name string) string

ReadCookie reads a cookie by name from the request, verifies its signature, and returns the original untampered value. It expects the cookie value to be in the "encodedValue|signature" format. ReadCookie는 요청(request)으로부터 지정한 이름(name)의 쿠키를 읽어, 서명을 확인하고 위변조되지 않은 원본 값을 반환합니다. 쿠키 값은 "encodedValue|signature" 형식이어야 합니다.

func (*CookieManager) ReadFlash

func (cm *CookieManager) ReadFlash(w http.ResponseWriter, r *http.Request, name string) string

ReadFlash implements flash cookie functionality. A flash cookie is read once and then automatically deleted. It's useful for one-time messages like notifications. ReadFlash는 플래시 쿠키 기능을 구현합니다. 플래시 쿠키는 한 번 읽은 후 자동으로 삭제되어 일회성 메시지(알림 등) 처리에 유용합니다.

func (*CookieManager) SetCookie

func (cm *CookieManager) SetCookie(w http.ResponseWriter, name, value string, maxAge int)

SetCookie creates a signed cookie with the specified name, value, and maxAge, and sets it in the HTTP response. The cookie value is stored in the format "base64-encoded-value|signature". SetCookie는 지정한 이름(name), 값(value), 유효기간(maxAge)을 갖는 서명된 쿠키를 생성하여 HTTP 응답(response)에 설정합니다. 쿠키 값은 "base64로 인코딩된 값|서명" 형식으로 저장됩니다.

Jump to

Keyboard shortcuts

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