-
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.
Leverage Mattress | Refactor Config (#164)
- Loading branch information
1 parent
ddb0145
commit 1405dc1
Showing
22 changed files
with
420 additions
and
196 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
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,7 @@ | ||
package config | ||
|
||
type ApplicationSettings struct { | ||
Port uint16 `yaml:"port"` | ||
Host string `yaml:"host"` | ||
BaseUrl string `yaml:"baseurl"` | ||
} |
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,40 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
|
||
m "github.com/garrettladley/mattress" | ||
) | ||
|
||
type AuthSettings struct { | ||
AccessKey *m.Secret[string] | ||
RefreshKey *m.Secret[string] | ||
AccessTokenExpiry uint | ||
RefreshTokenExpiry uint | ||
} | ||
|
||
type intermediateAuthSettings struct { | ||
AccessKey string `yaml:"accesskey"` | ||
RefreshKey string `yaml:"refreshkey"` | ||
AccessTokenExpiry uint `yaml:"accesstokenexpiry"` | ||
RefreshTokenExpiry uint `yaml:"refreshtokenexpiry"` | ||
} | ||
|
||
func (int *intermediateAuthSettings) into() (*AuthSettings, error) { | ||
accessToken, err := m.NewSecret(int.AccessKey) | ||
if err != nil { | ||
return nil, errors.New("failed to create secret from access key") | ||
} | ||
|
||
refreshToken, err := m.NewSecret(int.RefreshKey) | ||
if err != nil { | ||
return nil, errors.New("failed to create secret from refresh key") | ||
} | ||
|
||
return &AuthSettings{ | ||
AccessKey: accessToken, | ||
RefreshKey: refreshToken, | ||
AccessTokenExpiry: int.AccessTokenExpiry, | ||
RefreshTokenExpiry: int.RefreshTokenExpiry, | ||
}, nil | ||
} |
Oops, something went wrong.