This repository was archived by the owner on Jun 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Streamlines API Architecture and Enhances Authentication #45
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f75c4ab
Refactors API and enhances authentication
FinnTheHero 302aa4c
Refactor: Streamlines package structure and introduces token cache
FinnTheHero b4e77fb
Refactors JWT token handling
FinnTheHero 64cc661
Refactor: Move token generation to `middleware/token` package
FinnTheHero 7763590
Feat: Implement automatic token refresh and refresh token endpoint
FinnTheHero 6d71b50
Refactor: Streamline token validation middleware and handlers
FinnTheHero d3527cf
chore: Update build artifact name in air.toml
FinnTheHero cf265d6
chore: Exclude .github directory from air watch
FinnTheHero a709ac9
feat(common): Add GetDomains utility function
FinnTheHero 67a7a60
refactor(domain): Rename token config struct to LookupUser
FinnTheHero a1cfb8a
refactor(jwt): Use `any` type for jwt.ParseWithClaims callbacks
FinnTheHero 4d34430
refactor(middleware): Split token validation and user lookup
FinnTheHero 8395362
feat(middleware): Adapt token middleware usage to new design
FinnTheHero 7d0e5c6
feat(server): Use GetDomains for CORS configuration
FinnTheHero 7903ab6
feat: Extract chapter processing to processChap function
FinnTheHero 843e1b1
refactor: Reorder chapters and use processChap in CreateNovelFromEPUB
FinnTheHero 1935819
feat: Prefix all API routes with `/api/`
FinnTheHero 1a36cba
Fix: Handle empty domains slice when initializing in debug mode
FinnTheHero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "log" | ||
| "net/http" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/joho/godotenv" | ||
| ) | ||
|
|
@@ -24,3 +25,14 @@ func GetEnvVariable(v string) string { | |
|
|
||
| return env_variable | ||
| } | ||
|
|
||
| func GetDomains(v string) []string { | ||
| env_variable := os.Getenv(v) | ||
| if env_variable == "" { | ||
| log.Fatal(&Error{Err: errors.New("Environmental Variable " + v + " Not Found"), Status: http.StatusNotFound}) | ||
| } | ||
|
|
||
| result := strings.Split(env_variable, ",") | ||
|
|
||
| return result | ||
|
||
| } | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
api/internal/common/river/client.go → api/common/river/client.go
This file contains hidden or 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
api/internal/infrastructure/client/client.go → api/internal/database/client/client.go
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...al/infrastructure/collections/chapters.go → ...internal/database/collections/chapters.go
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...rnal/infrastructure/collections/novels.go → api/internal/database/collections/novels.go
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ernal/infrastructure/collections/users.go → api/internal/database/collections/users.go
This file contains hidden or 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 hidden or 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,52 @@ | ||
| package domain | ||
|
|
||
| import ( | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/golang-jwt/jwt/v5" | ||
| ) | ||
|
|
||
| type Claims struct { | ||
| ID string `json:"id"` | ||
| Email string `json:"email"` | ||
| Type string `json:"type"` | ||
| jwt.RegisteredClaims | ||
| } | ||
|
|
||
| type TokenConfig struct { | ||
| SigningKey string | ||
| AccessTTL time.Duration | ||
| RefreshTTL time.Duration | ||
| Issuer string // e.g., "your-app-name" | ||
| Audience string // e.g., "your-app-users" | ||
| } | ||
|
|
||
| type TokenPair struct { | ||
| AccessToken string `json:"access_token"` | ||
| RefreshToken string `json:"refresh_token"` | ||
| ExpiresAt time.Time `json:"expires_at"` | ||
| TokenType string `json:"token_type"` | ||
| } | ||
|
|
||
| // TokenCache interface for optional token caching | ||
| type TokenCache interface { | ||
| Get(key string) (any, bool) | ||
| Set(key string, value any, duration time.Duration) | ||
| Delete(key string) | ||
| } | ||
|
|
||
| type LookupUser struct { | ||
| Cache TokenCache | ||
| CacheDuration time.Duration | ||
| } | ||
|
|
||
| type InMemoryCache struct { | ||
| mu sync.RWMutex | ||
| items map[string]cacheItem | ||
| } | ||
|
|
||
| type cacheItem struct { | ||
| value any | ||
| expiresAt time.Time | ||
| } |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatal will terminate the program immediately, but the Error struct with Status field suggests this should return an error instead of calling log.Fatal