feat: custom token expires in

pull/1831/head
Noah Hsu 2022-09-27 14:05:00 +08:00
parent b7479651e1
commit 9d9c79179b
3 changed files with 18 additions and 19 deletions

View File

@ -1,7 +1,6 @@
package bootstrap
import (
"io/ioutil"
"os"
"path/filepath"
@ -25,7 +24,7 @@ func InitConfig() {
log.Fatalf("failed to create default config file")
}
} else {
configBytes, err := ioutil.ReadFile(flags.Config)
configBytes, err := os.ReadFile(flags.Config)
if err != nil {
log.Fatalf("reading config file error: %+v", err)
}

View File

@ -32,32 +32,32 @@ type LogConfig struct {
}
type Config struct {
Force bool `json:"force" env:"FORCE"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
SiteURL string `json:"site_url" env:"SITE_URL"`
Cdn string `json:"cdn" env:"CDN"`
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
Log LogConfig `json:"log"`
Force bool `json:"force" env:"FORCE"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
SiteURL string `json:"site_url" env:"SITE_URL"`
Cdn string `json:"cdn" env:"CDN"`
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
Log LogConfig `json:"log"`
}
func DefaultConfig() *Config {
return &Config{
Address: "0.0.0.0",
Port: 5244,
JwtSecret: random.String(16),
Cdn: "",
TempDir: "data/temp",
Address: "0.0.0.0",
Port: 5244,
JwtSecret: random.String(16),
TokenExpiresIn: 48,
TempDir: "data/temp",
Database: Database{
Type: "sqlite3",
Port: 0,
TablePrefix: "x_",
DBFile: "data/data.db",
},
// CaCheExpiration: 30,
Log: LogConfig{
Enable: true,
Name: "log/log.log",

View File

@ -18,7 +18,7 @@ func GenerateToken(username string) (tokenString string, err error) {
claim := UserClaims{
Username: username,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(12 * time.Hour)),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(48 * time.Hour)),
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
}}