package session

import (
	"time"

	libConfig "nms_nbi/restagent/config"
	"nms_nbi/src/framework/redis"

	"github.com/gin-gonic/gin"
)

// SessionHeader 旧登录方式token头
func SessionHeader() gin.HandlerFunc {
	return func(c *gin.Context) {
		// 读取登录生成的会话token
		token, _ := redis.Get("", "session_token")
		if token != "" {
			// 过期时间单位秒 配置1800是半小时
			expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
			redis.SetByExpire("", "session_token", token, expireTime)
			c.Request.Header.Set("Accesstoken", token)
		}

		// Accesstoken: omc-ce4d0a86-8515-ad51-3249-4913c95f8e34
		// 调用下一个处理程序
		c.Next()

	}
}
