-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
175 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
func New() *Config { | ||
return &Config{ | ||
DB: DB{ | ||
Host: os.Getenv("DB_HOST"), | ||
Port: os.Getenv("DB_PORT"), | ||
Name: os.Getenv("DB_NAME"), | ||
User: os.Getenv("DB_USER"), | ||
Password: os.Getenv("DB_PASSWORD"), | ||
}, | ||
JWT: JWT{ | ||
AccessTokenKey: os.Getenv("JWT_ACCESS_TOKEN_KEY"), | ||
RefreshTokenKey: os.Getenv("JWT_REFRESH_TOKEN_KEY"), | ||
}, | ||
Server: Server{ | ||
Port: os.Getenv("SERVER_PORT"), | ||
KeyPath: os.Getenv("SERVER_KEY_PATH"), | ||
CertPath: os.Getenv("SERVER_CERT_PATH"), | ||
CookieDomain: os.Getenv("COOKIE_DOMAIN"), | ||
AllowedOrigins: strings.Split(os.Getenv("CORS_ALLOWED_ORIGIN"), ","), | ||
}, | ||
} | ||
} | ||
|
||
type Config struct { | ||
DB DB | ||
JWT JWT | ||
Server Server | ||
} | ||
|
||
type DB struct { | ||
Host string | ||
Port string | ||
Name string | ||
User string | ||
Password string | ||
} | ||
|
||
type JWT struct { | ||
AccessTokenKey string | ||
RefreshTokenKey string | ||
} | ||
|
||
type Server struct { | ||
Port string | ||
KeyPath string | ||
CertPath string | ||
CookieDomain string | ||
AllowedOrigins []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package jwt | ||
|
||
import ( | ||
"os" | ||
|
||
"go.uber.org/fx" | ||
|
||
"github.com/crlssn/getstronger/apps/backend/pkg/config" | ||
) | ||
|
||
func Module() fx.Option { | ||
return fx.Provide( | ||
func() *Manager { | ||
return NewManager([]byte(os.Getenv("JWT_ACCESS_TOKEN_KEY")), []byte(os.Getenv("JWT_REFRESH_TOKEN_KEY"))) | ||
func(c *config.Config) *Manager { | ||
return NewManager([]byte(c.JWT.AccessTokenKey), []byte(c.JWT.RefreshTokenKey)) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package interceptors | ||
|
||
import ( | ||
"connectrpc.com/connect" | ||
"go.uber.org/fx" | ||
) | ||
|
||
const fxGroupInterceptors = `group:"interceptors"` | ||
|
||
func Module() fx.Option { | ||
return fx.Options( | ||
fx.Provide( | ||
// Annotate the interceptors to provide a slice of their interface. | ||
fx.Annotate( | ||
newAuth, | ||
fx.ResultTags(fxGroupInterceptors), | ||
), | ||
fx.Annotate( | ||
newValidator, | ||
fx.ResultTags(fxGroupInterceptors), | ||
), | ||
fx.Annotate( | ||
provideHandlerOptions, | ||
fx.ParamTags(fxGroupInterceptors), | ||
), | ||
), | ||
) | ||
} | ||
|
||
func provideHandlerOptions(i []Interceptor) []connect.HandlerOption { | ||
opts := make([]connect.HandlerOption, 0, len(i)) | ||
for _, j := range i { | ||
opts = append(opts, connect.WithInterceptors(j.Unary())) | ||
} | ||
return opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.