Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/LAA-Software-Engineering/golang-rest-api-template
/ functions
Functions
337 in github.com/LAA-Software-Engineering/golang-rest-api-template
⨍
Functions
337
◇
Types & classes
38
↓ 60 callers
Method
Set
(ctx context.Context, key string, value interface{}, expiration time.Duration)
pkg/cache/cache.go:23
↓ 39 callers
Function
Write
Write responds with a JSON error body and the given HTTP status. The caller should return immediately after (handlers do not abort the Gin chain).
pkg/httperr/httperr.go:12
↓ 38 callers
Method
Error
()
pkg/api/book_routes_auth_test.go:229
↓ 34 callers
Method
EXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/cache/cache_mock.go:41
↓ 34 callers
Function
NewBookHandler
NewBookHandler wires persistence and cache into book HTTP handlers.
pkg/api/books.go:42
↓ 30 callers
Function
NewMockCache
NewMockCache creates a new mock instance.
pkg/cache/cache_mock.go:34
↓ 28 callers
Method
Get
(ctx context.Context, key string)
pkg/cache/cache.go:22
↓ 23 callers
Function
NewMockBookPersistence
NewMockBookPersistence creates a new mock instance.
pkg/repository/mock_persistence.go:32
↓ 21 callers
Function
NewGormBookStore
NewGormBookStore returns a BookPersistence backed by db.
pkg/repository/book_gorm.go:17
↓ 19 callers
Method
Create
(book *models.Book)
pkg/repository/book.go:10
↓ 18 callers
Function
withBookActor
withBookActor injects the authenticated user id as JWTAuth would (for handler tests).
pkg/api/books_test.go:33
↓ 16 callers
Function
NewBookService
NewBookService constructs a BookService.
pkg/service/book_service.go:42
↓ 14 callers
Function
BooksListDataCacheKey
BooksListDataCacheKey is the Redis key for a cached books list page (tests and docs).
pkg/service/book_service.go:30
↓ 14 callers
Function
GenerateToken
GenerateToken issues an HS256 JWT with username and user_id claims. userID must be non-zero (database primary key of the authenticated user).
pkg/auth/auth.go:135
↓ 12 callers
Function
APIKeyAuth
APIKeyAuth returns Gin middleware that validates the X-API-Key header against the configured secret using a constant-time comparison.
pkg/middleware/api_key.go:89
↓ 12 callers
Function
IsBookNotFound
IsBookNotFound reports whether err is a missing-book lookup from GORM.
pkg/repository/book_gorm.go:89
↓ 12 callers
Function
redisOptionsFromEnv
()
pkg/cache/cache.go:41
↓ 11 callers
Method
EXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/repository/mock_persistence.go:39
↓ 11 callers
Function
SetJWTSigningKey
SetJWTSigningKey configures the symmetric key used to sign and verify JWTs. It must be called once during application startup with a secret of at leas
pkg/auth/auth.go:55
↓ 10 callers
Method
FirstByID
(id uint)
pkg/repository/book.go:11
↓ 10 callers
Function
HashPassword
(password string)
pkg/auth/auth.go:102
↓ 10 callers
Function
JWTAuth
JWTAuth returns Gin middleware that requires a valid Bearer JWT signed with HMAC-SHA256 using the application's JWT secret. Other algorithms are rejec
pkg/middleware/jwt_auth.go:20
↓ 10 callers
Function
JWTSigningKey
JWTSigningKey returns a copy of the configured JWT HMAC secret, or nil if SetJWTSigningKey has not completed successfully.
pkg/auth/auth.go:69
↓ 10 callers
Function
NewUserHandler
NewUserHandler wires persistence into user HTTP handlers.
pkg/api/user.go:27
↓ 10 callers
Function
testBookDB
(t *testing.T)
pkg/repository/book_gorm_test.go:14
↓ 9 callers
Function
Abort
Abort responds with a JSON error body, sets the HTTP status, and aborts the Gin chain so no later handlers run. Use in middleware.
pkg/httperr/httperr.go:21
↓ 9 callers
Method
Incr
(ctx context.Context, key string)
pkg/cache/cache.go:24
↓ 8 callers
Method
Create
(book *models.Book)
pkg/repository/book_gorm.go:27
↓ 8 callers
Method
FirstByID
(id uint)
pkg/repository/book_gorm.go:31
↓ 8 callers
Function
NewGormUserStore
NewGormUserStore returns a UserPersistence backed by db.
pkg/repository/user_gorm.go:19
↓ 7 callers
Method
ListBooks
ListBooks returns books for offset/limit using Redis list cache and singleflight on miss.
pkg/service/book_service.go:71
↓ 7 callers
Function
NewUserService
NewUserService constructs a UserService.
pkg/service/user_service.go:31
↓ 7 callers
Function
OK
OK writes HTTP 200 with the standard JSON envelope {"data": <payload>}.
pkg/httpresp/httpresp.go:14
↓ 6 callers
Function
IsUserNotFound
IsUserNotFound reports whether err is a missing-user lookup from GORM.
pkg/repository/user_gorm.go:57
↓ 6 callers
Method
Register
Register creates a new user account.
pkg/service/user_service.go:55
↓ 6 callers
Function
isUsernameUniqueConstraintError
(err error)
pkg/repository/user_gorm.go:42
↓ 6 callers
Function
testRouterAPIKeyOnly
(t *testing.T)
pkg/middleware/api_key_test.go:16
↓ 5 callers
Function
JWTKeyFunc
JWTKeyFunc returns a jwt.Keyfunc for ParseWithClaims that only accepts tokens signed with HMAC-SHA256 using key. Any other signing method (including "
pkg/auth/auth.go:93
↓ 5 callers
Method
Login
Login validates credentials and returns a JWT token string.
pkg/service/user_service.go:36
↓ 5 callers
Function
NewMockUserPersistence
NewMockUserPersistence creates a new mock instance.
pkg/repository/mock_persistence.go:144
↓ 5 callers
Function
SetAPISecretKey
SetAPISecretKey configures the expected raw value for the X-API-Key header. It must be called during application startup with a non-empty secret of at
pkg/middleware/api_key.go:32
↓ 5 callers
Function
create_book
(jwt_token)
tests/e2e.py:49
↓ 5 callers
Function
parseIDParam
(c *gin.Context)
pkg/api/books.go:46
↓ 5 callers
Function
testRouterJWTAuthOnly
(t *testing.T)
pkg/middleware/jwt_auth_test.go:27
↓ 4 callers
Function
GetRequestID
GetRequestID returns the request id stored in gin context.
pkg/middleware/request_id.go:63
↓ 4 callers
Function
MaxRequestBody
1 MiB MaxRequestBody returns middleware that caps how many bytes handlers may read from the request body for POST, PUT, and PATCH. Larger bodies yield
pkg/middleware/max_body.go:16
↓ 4 callers
Function
apiSecretCopy
()
pkg/middleware/api_key.go:44
↓ 4 callers
Method
bumpListCacheGeneration
bumpListCacheGeneration invalidates cached list pages by incrementing a global generation counter (BooksListCacheGenKey). Cached keys embed the genera
pkg/service/book_service.go:63
↓ 4 callers
Function
configureTrustedProxies
configureTrustedProxies sets which upstreams may influence ClientIP via X-Forwarded-For and related headers. If GIN_TRUSTED_PROXIES is unset or blank,
pkg/api/router.go:73
↓ 4 callers
Function
contextUserID
contextUserID returns the authenticated users.id set by middleware.JWTAuth.
pkg/api/books.go:88
↓ 4 callers
Function
fmtError
(sentinel error, cause error)
pkg/service/user_service.go:70
↓ 4 callers
Function
getenvPositiveDuration
(key string, def time.Duration)
pkg/database/db.go:39
↓ 4 callers
Function
getenvPositiveInt
(key string, def int)
pkg/database/db.go:26
↓ 4 callers
Function
requestContextTimeoutDurationFromEnv
()
pkg/middleware/request_timeout.go:39
↓ 3 callers
Method
Create
(user *models.User)
pkg/repository/user_gorm.go:31
↓ 3 callers
Function
Created
Created writes HTTP 201 with the standard JSON envelope {"data": <payload>}.
pkg/httpresp/httpresp.go:22
↓ 3 callers
Method
DeleteByID
(id uint)
pkg/repository/book.go:14
↓ 3 callers
Method
List
(offset, limit int)
pkg/repository/book_gorm.go:21
↓ 3 callers
Method
Ping
(ctx context.Context)
pkg/api/probes.go:65
↓ 3 callers
Method
ReplaceBook
ReplaceBook replaces title and author when actorID owns the book (PUT semantics).
pkg/service/book_service.go:124
↓ 3 callers
Function
RequestContextTimeout
RequestContextTimeout returns middleware that attaches a derived context.WithTimeout to c.Request, so handlers and services using c.Request.Context()
pkg/middleware/request_timeout.go:19
↓ 3 callers
Function
RequestID
RequestID ensures every request has a stable request id.
pkg/middleware/request_id.go:43
↓ 3 callers
Function
durationFromEnv
(key string, defaultVal time.Duration)
pkg/cache/cache.go:115
↓ 3 callers
Function
mongoConnectionURI
()
pkg/database/mongo.go:13
↓ 3 callers
Function
pingPostgres
(ctx context.Context, db *gorm.DB)
pkg/api/probes.go:52
↓ 3 callers
Function
testBookWriteMiddlewareStack
testBookWriteMiddlewareStack mirrors NewRouter book mutation middleware so JWT requirements stay aligned with production routes.
pkg/api/book_routes_auth_test.go:19
↓ 3 callers
Function
testUserDB
(t *testing.T)
pkg/repository/user_gorm_test.go:15
↓ 2 callers
Function
ClearJWTSigningKeyForTesting
ClearJWTSigningKeyForTesting drops the configured signing key. It is only intended for tests that cover misconfiguration; callers must restore a valid
pkg/auth/auth.go:83
↓ 2 callers
Method
CreateBook
CreateBook persists a new book owned by ownerID and bumps the list cache generation.
pkg/service/book_service.go:109
↓ 2 callers
Method
DeleteBook
DeleteBook removes a book when actorID owns it, then bumps list cache generation.
pkg/service/book_service.go:158
↓ 2 callers
Method
DeleteByID
(id uint)
pkg/repository/book_gorm.go:80
↓ 2 callers
Method
FindByUsername
(username string)
pkg/repository/user_gorm.go:23
↓ 2 callers
Function
GenerateRandomKey
()
pkg/auth/auth.go:165
↓ 2 callers
Method
Get
Get mocks base method.
pkg/cache/cache_mock.go:65
↓ 2 callers
Method
GetBook
GetBook returns a book by id or gorm.ErrRecordNotFound-compatible error from the store.
pkg/service/book_service.go:119
↓ 2 callers
Function
GetRequestIDFromContext
GetRequestIDFromContext reads the request id from context.
pkg/middleware/request_id.go:76
↓ 2 callers
Method
List
(offset, limit int)
pkg/repository/book.go:9
↓ 2 callers
Function
NewDatabase
NewDatabase opens PostgreSQL using POSTGRES_* environment variables, retries on failure, runs AutoMigrate for application models, and configures the u
pkg/database/db.go:77
↓ 2 callers
Method
PatchBook
PatchBook applies a partial update for any non-nil title/author pointers (PATCH semantics).
pkg/service/book_service.go:141
↓ 2 callers
Method
PatchFields
PatchFields updates only non-nil pointer fields (partial update).
pkg/repository/book_gorm.go:53
↓ 2 callers
Method
UpdateFields
(id uint, title, author string)
pkg/repository/book_gorm.go:39
↓ 2 callers
Function
_require_env
(name: str)
tests/e2e.py:8
↓ 2 callers
Function
configureConnPool
configureConnPool applies *sql.DB pool settings from POSTGRES_* env vars (with sane defaults). max idle connections is capped at max open.
pkg/database/db.go:54
↓ 2 callers
Function
envTruthy
envTruthy reports whether the named environment variable is set to a conventional affirmative value (1, true, yes, on), case-insensitive.
pkg/cache/cache.go:106
↓ 2 callers
Function
get_book
(book_id, jwt_token)
tests/e2e.py:70
↓ 2 callers
Function
pingMongo
(ctx context.Context, col *mongo.Collection)
pkg/api/probes.go:82
↓ 2 callers
Function
pingRedis
(ctx context.Context, c cache.Cache)
pkg/api/probes.go:68
↓ 1 callers
Function
ClearAPISecretKeyForTesting
ClearAPISecretKeyForTesting removes the configured API secret. Intended only for tests; callers must restore a valid key (for example via t.Cleanup).
pkg/middleware/api_key.go:57
↓ 1 callers
Function
Cors
()
pkg/middleware/cors.go:10
↓ 1 callers
Method
CreateBook
(c *gin.Context)
pkg/api/books.go:30
↓ 1 callers
Method
DeleteBook
(c *gin.Context)
pkg/api/books.go:34
↓ 1 callers
Method
EXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/repository/mock_persistence.go:151
↓ 1 callers
Method
FindByUsername
(username string)
pkg/repository/user.go:7
↓ 1 callers
Method
Healthcheck
(c *gin.Context)
pkg/api/books.go:28
↓ 1 callers
Function
Logger
(logger *zap.Logger, collection *mongo.Collection)
pkg/middleware/logger.go:69
↓ 1 callers
Function
NewRedisClient
NewRedisClient builds a go-redis client from environment variables. See redisOptionsFromEnv for supported keys and defaults.
pkg/cache/cache.go:33
↓ 1 callers
Function
NewRouter
NewRouter builds the Gin engine with middleware, Swagger, and API routes.
pkg/api/router.go:26
↓ 1 callers
Method
PatchBook
(c *gin.Context)
pkg/api/books.go:33
↓ 1 callers
Method
PatchFields
(id uint, title, author *string)
pkg/repository/book.go:13
↓ 1 callers
Function
RateLimiter
(r rate.Limit, b int)
pkg/middleware/rate_limit.go:11
next →
1–100 of 337, ranked by callers