func (s *Session) WriteCookie(cv string) error {
	s.cookie = &http.Cookie{
		Value:    cv,
		Name:     s.manager.opts.CookieName,
		Domain:   s.manager.opts.CookieDomain,
		Path:     s.manager.opts.CookiePath,
		Secure:   s.manager.opts.IsSecureCookie,
		HttpOnly: s.manager.opts.IsHTTPOnlyCookie,
		SameSite: s.manager.opts.SameSite,
	}
	if s.manager.opts.CookieLifetime != 0 {
		s.cookie.Expires = time.Now().Add(s.manager.opts.CookieLifetime)
	}
	return s.manager.setCookieCb(s.cookie, s.writer)
}
WriteCookie updates the cookie and calls `SetCookie` callback.
This method can also be used by store to update cookie whenever the cookie value changes.
package simplesessions
import (
	"crypto/rand"
	"errors"
	"net/http"
	"time"
	"unicode"
)
type Session struct {
	values map[string]interface{}
	manager *Manager
	cookie *http.Cookie
	reader interface{}
	writer interface{}
	isSet bool
}
var (
	ErrInvalidSession = errors.New("simplesession: invalid session")
	ErrFieldNotFound = errors.New("simplesession: session field not found in store")
	ErrAssertType = errors.New("simplesession: invalid type assertion")
	ErrNil = errors.New("simplesession: nil returned")
	dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)
func NewSession(m *Manager, r, w interface{}) (*Session, error) {
	var (
		err  error
		sess = &Session{
			manager: m,
			reader:  r,
			writer:  w,
			values:  make(map[string]interface{}),
		}
	)
	sess.cookie, err = m.getCookieCb(m.opts.CookieName, r)
	if err == http.ErrNoCookie {
		if m.opts.DisableAutoSet {
			return sess, nil
		}
		cv, err := m.store.Create(sess)
		if err != nil {
			return nil, err
		}
		if err := sess.WriteCookie(cv); err != nil {
			return nil, err
		}
		sess.isSet = true
	} else if err != nil {
		return nil, err
	}
	if isValid, err := m.store.IsValid(sess, sess.cookie.Value); err != nil {
		return nil, err
	} else if !isValid {
		return nil, ErrInvalidSession
	}
	sess.isSet = true
	return sess, nil
}
func (s *Session) GenerateRandomString(n int) (string, error) {
	var bytes = make([]byte, n)
	if _, err := rand.Read(bytes); err != nil {
		return "", err
	}
	for k, v := range bytes {
		bytes[k] = dictionary[v%byte(len(dictionary))]
	}
	return string(bytes), nil
}
func (s *Session) IsValidRandomString(val string) bool {
	return s.isAlphaNum(val)
}
func (s *Session) isAlphaNum(val string) bool {
	for _, r := range val {
		if !unicode.IsDigit(r) && !unicode.IsLetter(r) {
			return false
		}
	}
	return true
}