Skip to content

Commit

Permalink
feat: custom token expires in
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 27, 2022
1 parent b747965 commit 9d9c791
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
3 changes: 1 addition & 2 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bootstrap

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -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)
}
Expand Down
32 changes: 16 additions & 16 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion server/common/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}}
Expand Down

0 comments on commit 9d9c791

Please sign in to comment.