ginsession

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: Apache-2.0 Imports: 9 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 Redis

func Redis() gin.HandlerFunc

Types

type Config

type Config struct {
	Redis      string `config:"redis"`
	CookieName string `config:"cookieName" desc:"cookie name"`
	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) Redis

func (s *GinSession) Redis() 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