ginsession

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ginsession is gin server session middleware.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Default = StdConfig("default").Build()
)

Functions

func Cookie() gin.HandlerFunc

func CookieName added in v1.0.10

func CookieName() string

func CookieNames added in v1.0.10

func CookieNames() []string

func Redis

func Redis(serializers ...serializer.SessionSerializer) gin.HandlerFunc

Types

type Config

type Config struct {
	Redis       string   `config:"redis"`
	CookieName  string   `config:"cookieName" desc:"cookie name"`
	CookieNames []string `config:"cookieNames" desc:"cookie names"`
	KeyPair     string   `config:"keyPair" desc:"cookie value encrypt key pair"`
	KeyPrefix   string   `config:"keyPrefix" desc:"redis save key prefix"`
	MaxLen      int      `config:"maxLen" desc:"max val length"`
	// contains filtered or unexported fields
}

Config 配置

func DefaultConfig

func DefaultConfig(key string) *Config

DefaultConfig 默认配置

func StdConfig

func StdConfig(key string, optionFunc ...OptionFunc) *Config

StdConfig 标准配置

func (*Config) Build

func (c *Config) Build() *GinSession

Build 构建实例

func (*Config) Path

func (c *Config) Path() string

Path 实例配置目录

type GinSession

type GinSession struct {
	// contains filtered or unexported fields
}

func (*GinSession) Cookie

func (s *GinSession) Cookie() gin.HandlerFunc
Example
package main

import (
	"github.com/boxgo/box/pkg/logger"
	"github.com/boxgo/box/pkg/server/ginserver"
	"github.com/boxgo/box/pkg/server/ginserver/mid/ginsession"
)

func main() {
	ginserver.Use(ginsession.Cookie())
	ginserver.GET("/ping", func(ctx *ginserver.Context) {
		ctx.Data(200, "text/plain", []byte("pong"))
	})

	if err := ginserver.Run(); err != nil {
		logger.Fatal(err)
	}
}
Output:

func (*GinSession) CookieName added in v1.0.10

func (s *GinSession) CookieName() string

func (*GinSession) CookieNames added in v1.0.10

func (s *GinSession) CookieNames() []string

func (*GinSession) MockDel added in v1.0.22

func (s *GinSession) MockDel(sid string) (err error)

MockDel del session by sid

func (*GinSession) MockSet added in v1.0.22

func (s *GinSession) MockSet(value interface{}) (sid string, cookie string, err error)

MockSet set cookie and return redis sid key and cookie string

func (*GinSession) Redis

func (s *GinSession) Redis(serializers ...serializer.SessionSerializer) gin.HandlerFunc
Example
package main

import (
	"github.com/boxgo/box/pkg/logger"
	"github.com/boxgo/box/pkg/server/ginserver"
	"github.com/boxgo/box/pkg/server/ginserver/mid/ginsession"
)

func main() {
	ginserver.Use(ginsession.Redis())
	ginserver.GET("/ping", func(ctx *ginserver.Context) {
		ctx.Data(200, "text/plain", []byte("pong"))
	})

	if err := ginserver.Run(); err != nil {
		logger.Fatal(err)
	}
}
Output:

type OptionFunc

type OptionFunc func(*Config)

OptionFunc 选项信息

Jump to

Keyboard shortcuts

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