func (s *Session) GetSessionId(ctx *fasthttp.RequestCtx) string {
	cookieByte := ctx.Request.Header.Cookie(s.config.CookieName)
	if len(cookieByte) > 0 {
		return s.config.Decode(string(cookieByte))
	}
	if s.config.SessionIdInURLQuery {
		cookieFormValue := ctx.FormValue(s.config.SessionNameInUrlQuery)
		if len(cookieFormValue) > 0 {
			return s.config.Decode(string(cookieFormValue))
		}
	}
	if s.config.SessionIdInHttpHeader {
		cookieHeader := ctx.Request.Header.Peek(s.config.SessionNameInHttpHeader)
		if len(cookieHeader) > 0 {
			return s.config.Decode(string(cookieHeader))
		}
	}
	return ""
}
get session id
1. get session id by reading from cookie
2. get session id from query
3. get session id from http headers
package fasthttpsession
import (
	"errors"
	"fmt"
	"github.com/valyala/fasthttp"
	"time"
)
var version = "v0.0.1"
type Session struct {
	provider Provider
	config   *Config
	cookie   *Cookie
}
var providers = make(map[string]Provider)
func Register(providerName string, provider Provider) {
	if providers[providerName] != nil {
		panic("session register error, provider " + providerName + " already registered!")
	}
	if provider == nil {
		panic("session register error, provider " + providerName + " is nil!")
	}
	providers[providerName] = provider
}
func NewSession(cfg *Config) *Session {
	if cfg.CookieName == "" {
		cfg.CookieName = defaultCookieName
	}
	if cfg.GCLifetime == 0 {
		cfg.GCLifetime = defaultGCLifetime
	}
	if cfg.SessionLifetime == 0 {
		cfg.SessionLifetime = cfg.GCLifetime
	}
	if cfg.SessionIdGeneratorFunc == nil {
		cfg.SessionIdGeneratorFunc = cfg.defaultSessionIdGenerator
	}
	session := &Session{
		config: cfg,
		cookie: NewCookie(),
	}
	return session
}
func (s *Session) SetProvider(providerName string, providerConfig ProviderConfig) error {
	provider, ok := providers[providerName]
	if !ok {
		return errors.New("session set provider error, " + providerName + " not registered!")
	}
	err := provider.Init(s.config.SessionLifetime, providerConfig)
	if err != nil {
		return err
	}
	s.provider = provider
	if s.provider.NeedGC() {
		go func() {
			defer func() {
				e := recover()
				if e != nil {
					panic(errors.New(fmt.Sprintf("session gc crash, %v", e)))
				}
			}()
			s.gc()
		}()
	}
	return nil
}
func (s *Session) gc() {
	for {
		select {
		case <-time.After(time.Duration(s.config.GCLifetime) * time.Second):
			s.provider.GC()
		}
	}
}
func (s *Session) Start(ctx *fasthttp.RequestCtx) (sessionStore SessionStore, err error) {
	if s.provider == nil {
		return sessionStore, errors.New("session start error, not set provider")
	}
	sessionId := s.GetSessionId(ctx)
	if sessionId == "" {
		sessionId = s.config.SessionIdGenerator()
		if sessionId == "" {
			return sessionStore, errors.New("session generator sessionId is empty")
		}
	}
	sessionStore, err = s.provider.ReadStore(sessionId)
	if err != nil {
		return
	}
	encodeCookieValue := s.config.Encode(sessionId)
	s.cookie.Set(ctx,
		s.config.CookieName,
		encodeCookieValue,
		s.config.Domain,
		s.config.Expires,
		s.config.Secure)
	if s.config.SessionIdInHttpHeader {
		ctx.Request.Header.Set(s.config.SessionNameInHttpHeader, sessionId)
		ctx.Response.Header.Set(s.config.SessionNameInHttpHeader, sessionId)
	}
	return
}