Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e5ea95

Browse files
committed
added jwt authentication
1 parentc1114ba commit0e5ea95

File tree

14 files changed

+503
-16
lines changed

14 files changed

+503
-16
lines changed

‎controllers/auth.controller.go

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"strings"
7+
"time"
8+
9+
"github.com/gin-gonic/gin"
10+
"github.com/wpcodevo/golang-gorm-postgres/initializers"
11+
"github.com/wpcodevo/golang-gorm-postgres/models"
12+
"github.com/wpcodevo/golang-gorm-postgres/utils"
13+
"gorm.io/gorm"
14+
)
15+
16+
typeAuthControllerstruct {
17+
DB*gorm.DB
18+
}
19+
20+
funcNewAuthController(DB*gorm.DB)AuthController {
21+
returnAuthController{DB}
22+
}
23+
24+
// SignUp User
25+
func (ac*AuthController)SignUpUser(ctx*gin.Context) {
26+
varpayload*models.SignUpInput
27+
28+
iferr:=ctx.ShouldBindJSON(&payload);err!=nil {
29+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":err.Error()})
30+
return
31+
}
32+
33+
ifpayload.Password!=payload.PasswordConfirm {
34+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":"Passwords do not match"})
35+
return
36+
}
37+
38+
hashedPassword,err:=utils.HashPassword(payload.Password)
39+
iferr!=nil {
40+
ctx.JSON(http.StatusBadGateway, gin.H{"status":"error","message":err.Error()})
41+
return
42+
}
43+
44+
now:=time.Now()
45+
newUser:= models.User{
46+
Name:payload.Name,
47+
Email:strings.ToLower(payload.Email),
48+
Password:hashedPassword,
49+
Role:"user",
50+
Verified:true,
51+
Photo:payload.Photo,
52+
Provider:"local",
53+
CreatedAt:now,
54+
UpdatedAt:now,
55+
}
56+
57+
result:=ac.DB.Create(&newUser)
58+
59+
ifresult.Error!=nil {
60+
ctx.JSON(http.StatusBadGateway, gin.H{"status":"error","message":"Something bad happened"})
61+
return
62+
}
63+
64+
userResponse:=&models.UserResponse{
65+
ID:newUser.ID,
66+
Name:newUser.Name,
67+
Email:newUser.Email,
68+
Photo:newUser.Photo,
69+
Role:newUser.Role,
70+
Provider:newUser.Provider,
71+
CreatedAt:newUser.CreatedAt,
72+
UpdatedAt:newUser.UpdatedAt,
73+
}
74+
ctx.JSON(http.StatusCreated, gin.H{"status":"success","data": gin.H{"user":userResponse}})
75+
}
76+
77+
func (ac*AuthController)SignInUser(ctx*gin.Context) {
78+
varpayload*models.SignInInput
79+
80+
iferr:=ctx.ShouldBindJSON(&payload);err!=nil {
81+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":err.Error()})
82+
return
83+
}
84+
85+
varuser models.User
86+
result:=ac.DB.First(&user,"email = ?",strings.ToLower(payload.Email))
87+
ifresult.Error!=nil {
88+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":"Invalid email or Password"})
89+
return
90+
}
91+
92+
iferr:=utils.VerifyPassword(user.Password,payload.Password);err!=nil {
93+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":"Invalid email or Password"})
94+
return
95+
}
96+
97+
config,_:=initializers.LoadConfig(".")
98+
99+
// Generate Tokens
100+
access_token,err:=utils.CreateToken(config.AccessTokenExpiresIn,user.ID,config.AccessTokenPrivateKey)
101+
iferr!=nil {
102+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":err.Error()})
103+
return
104+
}
105+
106+
refresh_token,err:=utils.CreateToken(config.RefreshTokenExpiresIn,user.ID,config.RefreshTokenPrivateKey)
107+
iferr!=nil {
108+
ctx.JSON(http.StatusBadRequest, gin.H{"status":"fail","message":err.Error()})
109+
return
110+
}
111+
112+
ctx.SetCookie("access_token",access_token,config.AccessTokenMaxAge*60,"/","localhost",false,true)
113+
ctx.SetCookie("refresh_token",refresh_token,config.RefreshTokenMaxAge*60,"/","localhost",false,true)
114+
ctx.SetCookie("logged_in","true",config.AccessTokenMaxAge*60,"/","localhost",false,false)
115+
116+
ctx.JSON(http.StatusOK, gin.H{"status":"success","access_token":access_token})
117+
}
118+
119+
// Refresh Access Token
120+
func (ac*AuthController)RefreshAccessToken(ctx*gin.Context) {
121+
message:="could not refresh access token"
122+
123+
cookie,err:=ctx.Cookie("refresh_token")
124+
125+
iferr!=nil {
126+
ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"status":"fail","message":message})
127+
return
128+
}
129+
130+
config,_:=initializers.LoadConfig(".")
131+
132+
sub,err:=utils.ValidateToken(cookie,config.RefreshTokenPublicKey)
133+
iferr!=nil {
134+
ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"status":"fail","message":err.Error()})
135+
return
136+
}
137+
138+
varuser models.User
139+
result:=ac.DB.First(&user,"id = ?",fmt.Sprint(sub))
140+
ifresult.Error!=nil {
141+
ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"status":"fail","message":"the user belonging to this token no logger exists"})
142+
return
143+
}
144+
145+
access_token,err:=utils.CreateToken(config.AccessTokenExpiresIn,user.ID,config.AccessTokenPrivateKey)
146+
iferr!=nil {
147+
ctx.AbortWithStatusJSON(http.StatusForbidden, gin.H{"status":"fail","message":err.Error()})
148+
return
149+
}
150+
151+
ctx.SetCookie("access_token",access_token,config.AccessTokenMaxAge*60,"/","localhost",false,true)
152+
ctx.SetCookie("logged_in","true",config.AccessTokenMaxAge*60,"/","localhost",false,false)
153+
154+
ctx.JSON(http.StatusOK, gin.H{"status":"success","access_token":access_token})
155+
}
156+
157+
func (ac*AuthController)LogoutUser(ctx*gin.Context) {
158+
ctx.SetCookie("access_token","",-1,"/","localhost",false,true)
159+
ctx.SetCookie("refresh_token","",-1,"/","localhost",false,true)
160+
ctx.SetCookie("logged_in","",-1,"/","localhost",false,false)
161+
162+
ctx.JSON(http.StatusOK, gin.H{"status":"success"})
163+
}

‎controllers/user.controller.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package controllers
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
"github.com/wpcodevo/golang-gorm-postgres/models"
8+
"gorm.io/gorm"
9+
)
10+
11+
typeUserControllerstruct {
12+
DB*gorm.DB
13+
}
14+
15+
funcNewUserController(DB*gorm.DB)UserController {
16+
returnUserController{DB}
17+
}
18+
19+
func (uc*UserController)GetMe(ctx*gin.Context) {
20+
currentUser:=ctx.MustGet("currentUser").(models.User)
21+
22+
userResponse:=&models.UserResponse{
23+
ID:currentUser.ID,
24+
Name:currentUser.Name,
25+
Email:currentUser.Email,
26+
Photo:currentUser.Photo,
27+
Role:currentUser.Role,
28+
Provider:currentUser.Provider,
29+
CreatedAt:currentUser.CreatedAt,
30+
UpdatedAt:currentUser.UpdatedAt,
31+
}
32+
33+
ctx.JSON(http.StatusOK, gin.H{"status":"success","data": gin.H{"user":userResponse}})
34+
}

‎go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ module github.com/wpcodevo/golang-gorm-postgres
33
go1.18
44

55
require (
6+
github.com/gin-contrib/corsv1.4.0
7+
github.com/gin-gonic/ginv1.8.1
8+
github.com/golang-jwt/jwtv3.2.2+incompatible
9+
github.com/google/uuidv1.1.2
610
github.com/spf13/viperv1.12.0
11+
golang.org/x/cryptov0.0.0-20220722155217-630584e8d5aa
712
gorm.io/driver/postgresv1.3.8
813
gorm.io/gormv1.23.8
914
)
1015

1116
require (
1217
github.com/fsnotify/fsnotifyv1.5.4// indirect
1318
github.com/gin-contrib/ssev0.1.0// indirect
14-
github.com/gin-gonic/ginv1.8.1// indirect
1519
github.com/go-playground/localesv0.14.0// indirect
1620
github.com/go-playground/universal-translatorv0.18.0// indirect
1721
github.com/go-playground/validator/v10v10.11.0// indirect
@@ -42,7 +46,6 @@ require (
4246
github.com/spf13/pflagv1.0.5// indirect
4347
github.com/subosito/gotenvv1.3.0// indirect
4448
github.com/ugorji/go/codecv1.2.7// indirect
45-
golang.org/x/cryptov0.0.0-20220722155217-630584e8d5aa// indirect
4649
golang.org/x/netv0.0.0-20220805013720-a33c5aa5df48// indirect
4750
golang.org/x/sysv0.0.0-20220804214406-8e32c043e418// indirect
4851
golang.org/x/textv0.3.7// indirect

‎go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
6666
github.com/frankban/quicktestv1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
6767
github.com/fsnotify/fsnotifyv1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
6868
github.com/fsnotify/fsnotifyv1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
69+
github.com/gin-contrib/corsv1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
70+
github.com/gin-contrib/corsv1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
6971
github.com/gin-contrib/ssev0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
7072
github.com/gin-contrib/ssev0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
7173
github.com/gin-gonic/ginv1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
@@ -75,18 +77,23 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
7577
github.com/go-gl/glfw/v3.3/glfwv0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
7678
github.com/go-kit/logv0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
7779
github.com/go-logfmt/logfmtv0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
80+
github.com/go-playground/assert/v2v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
7881
github.com/go-playground/assert/v2v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
7982
github.com/go-playground/localesv0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
8083
github.com/go-playground/localesv0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
8184
github.com/go-playground/universal-translatorv0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
8285
github.com/go-playground/universal-translatorv0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
86+
github.com/go-playground/validator/v10v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
8387
github.com/go-playground/validator/v10v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
8488
github.com/go-playground/validator/v10v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
8589
github.com/go-stack/stackv1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
90+
github.com/goccy/go-jsonv0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
8691
github.com/goccy/go-jsonv0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc=
8792
github.com/goccy/go-jsonv0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
8893
github.com/gofrs/uuidv4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
8994
github.com/gofrs/uuidv4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
95+
github.com/golang-jwt/jwtv3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
96+
github.com/golang-jwt/jwtv3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
9097
github.com/golang/glogv0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
9198
github.com/golang/groupcachev0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
9299
github.com/golang/groupcachev0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -141,6 +148,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
141148
github.com/google/pprofv0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
142149
github.com/google/pprofv0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
143150
github.com/google/renameiov0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
151+
github.com/google/uuidv1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
144152
github.com/google/uuidv1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
145153
github.com/googleapis/gax-go/v2v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
146154
github.com/googleapis/gax-go/v2v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
@@ -244,7 +252,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
244252
github.com/modern-go/reflect2v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
245253
github.com/pelletier/go-tomlv1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
246254
github.com/pelletier/go-tomlv1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
247-
github.com/pelletier/go-toml/v2v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU=
248255
github.com/pelletier/go-toml/v2v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
249256
github.com/pelletier/go-toml/v2v2.0.2 h1:+jQXlF3scKIcSEKkdHzXhCTDLPFi5r1wnK6yPS+49Gw=
250257
github.com/pelletier/go-toml/v2v2.0.2/go.mod h1:MovirKjgVRESsAvNZlAjtFwV867yGuwRkXbG66OzopI=
@@ -257,7 +264,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
257264
github.com/pmezard/go-difflibv1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
258265
github.com/prometheus/client_modelv0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
259266
github.com/rogpeppe/go-internalv1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
260-
github.com/rogpeppe/go-internalv1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
261267
github.com/rogpeppe/go-internalv1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
262268
github.com/rogpeppe/go-internalv1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
263269
github.com/rogpeppe/go-internalv1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
@@ -283,19 +289,19 @@ github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiu
283289
github.com/stretchr/objxv0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
284290
github.com/stretchr/objxv0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
285291
github.com/stretchr/objxv0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
292+
github.com/stretchr/objxv0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
286293
github.com/stretchr/testifyv1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
287294
github.com/stretchr/testifyv1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
288295
github.com/stretchr/testifyv1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
289296
github.com/stretchr/testifyv1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
290297
github.com/stretchr/testifyv1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
291298
github.com/stretchr/testifyv1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
292-
github.com/stretchr/testifyv1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
293299
github.com/stretchr/testifyv1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
294-
github.com/stretchr/testifyv1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
295300
github.com/stretchr/testifyv1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
301+
github.com/stretchr/testifyv1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
302+
github.com/stretchr/testifyv1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
296303
github.com/subosito/gotenvv1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
297304
github.com/subosito/gotenvv1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
298-
github.com/ugorji/gov1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
299305
github.com/ugorji/gov1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
300306
github.com/ugorji/go/codecv1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
301307
github.com/ugorji/go/codecv1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
@@ -335,8 +341,6 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
335341
golang.org/x/cryptov0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
336342
golang.org/x/cryptov0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
337343
golang.org/x/cryptov0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
338-
golang.org/x/cryptov0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
339-
golang.org/x/cryptov0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
340344
golang.org/x/cryptov0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
341345
golang.org/x/cryptov0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
342346
golang.org/x/expv0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -471,8 +475,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
471475
golang.org/x/sysv0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
472476
golang.org/x/sysv0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
473477
golang.org/x/sysv0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
474-
golang.org/x/sysv0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
475-
golang.org/x/sysv0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
476478
golang.org/x/sysv0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME=
477479
golang.org/x/sysv0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
478480
golang.org/x/termv0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
@@ -636,10 +638,10 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
636638
google.golang.org/protobufv1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
637639
google.golang.org/protobufv1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
638640
google.golang.org/protobufv1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
641+
google.golang.org/protobufv1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
639642
google.golang.org/protobufv1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
640643
google.golang.org/protobufv1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
641644
gopkg.in/check.v1v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
642-
gopkg.in/check.v1v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
643645
gopkg.in/check.v1v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
644646
gopkg.in/check.v1v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
645647
gopkg.in/check.v1v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
@@ -652,8 +654,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
652654
gopkg.in/yaml.v2v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
653655
gopkg.in/yaml.v3v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
654656
gopkg.in/yaml.v3v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
655-
gopkg.in/yaml.v3v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
656-
gopkg.in/yaml.v3v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
657657
gopkg.in/yaml.v3v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
658658
gopkg.in/yaml.v3v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
659659
gorm.io/driver/postgresv1.3.8 h1:8bEphSAB69t3odsCR4NDzt581iZEWQuRM27Cg6KgfPY=

‎initializers/loadEnv.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package initializers
22

33
import (
4+
"time"
5+
46
"github.com/spf13/viper"
57
)
68

@@ -13,6 +15,15 @@ type Config struct {
1315
ServerPortstring`mapstructure:"PORT"`
1416

1517
ClientOriginstring`mapstructure:"CLIENT_ORIGIN"`
18+
19+
AccessTokenPrivateKeystring`mapstructure:"ACCESS_TOKEN_PRIVATE_KEY"`
20+
AccessTokenPublicKeystring`mapstructure:"ACCESS_TOKEN_PUBLIC_KEY"`
21+
RefreshTokenPrivateKeystring`mapstructure:"REFRESH_TOKEN_PRIVATE_KEY"`
22+
RefreshTokenPublicKeystring`mapstructure:"REFRESH_TOKEN_PUBLIC_KEY"`
23+
AccessTokenExpiresIn time.Duration`mapstructure:"ACCESS_TOKEN_EXPIRED_IN"`
24+
RefreshTokenExpiresIn time.Duration`mapstructure:"REFRESH_TOKEN_EXPIRED_IN"`
25+
AccessTokenMaxAgeint`mapstructure:"ACCESS_TOKEN_MAXAGE"`
26+
RefreshTokenMaxAgeint`mapstructure:"REFRESH_TOKEN_MAXAGE"`
1627
}
1728

1829
funcLoadConfig(pathstring) (configConfig,errerror) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp