MCPcopy Create free account

hub / github.com/LAA-Software-Engineering/golang-rest-api-template / functions

Functions337 in github.com/LAA-Software-Engineering/golang-rest-api-template

↓ 60 callersMethodSet
(ctx context.Context, key string, value interface{}, expiration time.Duration)
pkg/cache/cache.go:23
↓ 39 callersFunctionWrite
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 callersMethodError
()
pkg/api/book_routes_auth_test.go:229
↓ 34 callersMethodEXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/cache/cache_mock.go:41
↓ 34 callersFunctionNewBookHandler
NewBookHandler wires persistence and cache into book HTTP handlers.
pkg/api/books.go:42
↓ 30 callersFunctionNewMockCache
NewMockCache creates a new mock instance.
pkg/cache/cache_mock.go:34
↓ 28 callersMethodGet
(ctx context.Context, key string)
pkg/cache/cache.go:22
↓ 23 callersFunctionNewMockBookPersistence
NewMockBookPersistence creates a new mock instance.
pkg/repository/mock_persistence.go:32
↓ 21 callersFunctionNewGormBookStore
NewGormBookStore returns a BookPersistence backed by db.
pkg/repository/book_gorm.go:17
↓ 19 callersMethodCreate
(book *models.Book)
pkg/repository/book.go:10
↓ 18 callersFunctionwithBookActor
withBookActor injects the authenticated user id as JWTAuth would (for handler tests).
pkg/api/books_test.go:33
↓ 16 callersFunctionNewBookService
NewBookService constructs a BookService.
pkg/service/book_service.go:42
↓ 14 callersFunctionBooksListDataCacheKey
BooksListDataCacheKey is the Redis key for a cached books list page (tests and docs).
pkg/service/book_service.go:30
↓ 14 callersFunctionGenerateToken
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 callersFunctionAPIKeyAuth
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 callersFunctionIsBookNotFound
IsBookNotFound reports whether err is a missing-book lookup from GORM.
pkg/repository/book_gorm.go:89
↓ 12 callersFunctionredisOptionsFromEnv
()
pkg/cache/cache.go:41
↓ 11 callersMethodEXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/repository/mock_persistence.go:39
↓ 11 callersFunctionSetJWTSigningKey
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 callersMethodFirstByID
(id uint)
pkg/repository/book.go:11
↓ 10 callersFunctionHashPassword
(password string)
pkg/auth/auth.go:102
↓ 10 callersFunctionJWTAuth
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 callersFunctionJWTSigningKey
JWTSigningKey returns a copy of the configured JWT HMAC secret, or nil if SetJWTSigningKey has not completed successfully.
pkg/auth/auth.go:69
↓ 10 callersFunctionNewUserHandler
NewUserHandler wires persistence into user HTTP handlers.
pkg/api/user.go:27
↓ 10 callersFunctiontestBookDB
(t *testing.T)
pkg/repository/book_gorm_test.go:14
↓ 9 callersFunctionAbort
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 callersMethodIncr
(ctx context.Context, key string)
pkg/cache/cache.go:24
↓ 8 callersMethodCreate
(book *models.Book)
pkg/repository/book_gorm.go:27
↓ 8 callersMethodFirstByID
(id uint)
pkg/repository/book_gorm.go:31
↓ 8 callersFunctionNewGormUserStore
NewGormUserStore returns a UserPersistence backed by db.
pkg/repository/user_gorm.go:19
↓ 7 callersMethodListBooks
ListBooks returns books for offset/limit using Redis list cache and singleflight on miss.
pkg/service/book_service.go:71
↓ 7 callersFunctionNewUserService
NewUserService constructs a UserService.
pkg/service/user_service.go:31
↓ 7 callersFunctionOK
OK writes HTTP 200 with the standard JSON envelope {"data": <payload>}.
pkg/httpresp/httpresp.go:14
↓ 6 callersFunctionIsUserNotFound
IsUserNotFound reports whether err is a missing-user lookup from GORM.
pkg/repository/user_gorm.go:57
↓ 6 callersMethodRegister
Register creates a new user account.
pkg/service/user_service.go:55
↓ 6 callersFunctionisUsernameUniqueConstraintError
(err error)
pkg/repository/user_gorm.go:42
↓ 6 callersFunctiontestRouterAPIKeyOnly
(t *testing.T)
pkg/middleware/api_key_test.go:16
↓ 5 callersFunctionJWTKeyFunc
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 callersMethodLogin
Login validates credentials and returns a JWT token string.
pkg/service/user_service.go:36
↓ 5 callersFunctionNewMockUserPersistence
NewMockUserPersistence creates a new mock instance.
pkg/repository/mock_persistence.go:144
↓ 5 callersFunctionSetAPISecretKey
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 callersFunctioncreate_book
(jwt_token)
tests/e2e.py:49
↓ 5 callersFunctionparseIDParam
(c *gin.Context)
pkg/api/books.go:46
↓ 5 callersFunctiontestRouterJWTAuthOnly
(t *testing.T)
pkg/middleware/jwt_auth_test.go:27
↓ 4 callersFunctionGetRequestID
GetRequestID returns the request id stored in gin context.
pkg/middleware/request_id.go:63
↓ 4 callersFunctionMaxRequestBody
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 callersFunctionapiSecretCopy
()
pkg/middleware/api_key.go:44
↓ 4 callersMethodbumpListCacheGeneration
bumpListCacheGeneration invalidates cached list pages by incrementing a global generation counter (BooksListCacheGenKey). Cached keys embed the genera
pkg/service/book_service.go:63
↓ 4 callersFunctionconfigureTrustedProxies
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 callersFunctioncontextUserID
contextUserID returns the authenticated users.id set by middleware.JWTAuth.
pkg/api/books.go:88
↓ 4 callersFunctionfmtError
(sentinel error, cause error)
pkg/service/user_service.go:70
↓ 4 callersFunctiongetenvPositiveDuration
(key string, def time.Duration)
pkg/database/db.go:39
↓ 4 callersFunctiongetenvPositiveInt
(key string, def int)
pkg/database/db.go:26
↓ 4 callersFunctionrequestContextTimeoutDurationFromEnv
()
pkg/middleware/request_timeout.go:39
↓ 3 callersMethodCreate
(user *models.User)
pkg/repository/user_gorm.go:31
↓ 3 callersFunctionCreated
Created writes HTTP 201 with the standard JSON envelope {"data": <payload>}.
pkg/httpresp/httpresp.go:22
↓ 3 callersMethodDeleteByID
(id uint)
pkg/repository/book.go:14
↓ 3 callersMethodList
(offset, limit int)
pkg/repository/book_gorm.go:21
↓ 3 callersMethodPing
(ctx context.Context)
pkg/api/probes.go:65
↓ 3 callersMethodReplaceBook
ReplaceBook replaces title and author when actorID owns the book (PUT semantics).
pkg/service/book_service.go:124
↓ 3 callersFunctionRequestContextTimeout
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 callersFunctionRequestID
RequestID ensures every request has a stable request id.
pkg/middleware/request_id.go:43
↓ 3 callersFunctiondurationFromEnv
(key string, defaultVal time.Duration)
pkg/cache/cache.go:115
↓ 3 callersFunctionmongoConnectionURI
()
pkg/database/mongo.go:13
↓ 3 callersFunctionpingPostgres
(ctx context.Context, db *gorm.DB)
pkg/api/probes.go:52
↓ 3 callersFunctiontestBookWriteMiddlewareStack
testBookWriteMiddlewareStack mirrors NewRouter book mutation middleware so JWT requirements stay aligned with production routes.
pkg/api/book_routes_auth_test.go:19
↓ 3 callersFunctiontestUserDB
(t *testing.T)
pkg/repository/user_gorm_test.go:15
↓ 2 callersFunctionClearJWTSigningKeyForTesting
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 callersMethodCreateBook
CreateBook persists a new book owned by ownerID and bumps the list cache generation.
pkg/service/book_service.go:109
↓ 2 callersMethodDeleteBook
DeleteBook removes a book when actorID owns it, then bumps list cache generation.
pkg/service/book_service.go:158
↓ 2 callersMethodDeleteByID
(id uint)
pkg/repository/book_gorm.go:80
↓ 2 callersMethodFindByUsername
(username string)
pkg/repository/user_gorm.go:23
↓ 2 callersFunctionGenerateRandomKey
()
pkg/auth/auth.go:165
↓ 2 callersMethodGet
Get mocks base method.
pkg/cache/cache_mock.go:65
↓ 2 callersMethodGetBook
GetBook returns a book by id or gorm.ErrRecordNotFound-compatible error from the store.
pkg/service/book_service.go:119
↓ 2 callersFunctionGetRequestIDFromContext
GetRequestIDFromContext reads the request id from context.
pkg/middleware/request_id.go:76
↓ 2 callersMethodList
(offset, limit int)
pkg/repository/book.go:9
↓ 2 callersFunctionNewDatabase
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 callersMethodPatchBook
PatchBook applies a partial update for any non-nil title/author pointers (PATCH semantics).
pkg/service/book_service.go:141
↓ 2 callersMethodPatchFields
PatchFields updates only non-nil pointer fields (partial update).
pkg/repository/book_gorm.go:53
↓ 2 callersMethodUpdateFields
(id uint, title, author string)
pkg/repository/book_gorm.go:39
↓ 2 callersFunction_require_env
(name: str)
tests/e2e.py:8
↓ 2 callersFunctionconfigureConnPool
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 callersFunctionenvTruthy
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 callersFunctionget_book
(book_id, jwt_token)
tests/e2e.py:70
↓ 2 callersFunctionpingMongo
(ctx context.Context, col *mongo.Collection)
pkg/api/probes.go:82
↓ 2 callersFunctionpingRedis
(ctx context.Context, c cache.Cache)
pkg/api/probes.go:68
↓ 1 callersFunctionClearAPISecretKeyForTesting
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 callersFunctionCors
()
pkg/middleware/cors.go:10
↓ 1 callersMethodCreateBook
(c *gin.Context)
pkg/api/books.go:30
↓ 1 callersMethodDeleteBook
(c *gin.Context)
pkg/api/books.go:34
↓ 1 callersMethodEXPECT
EXPECT returns an object that allows the caller to indicate expected use.
pkg/repository/mock_persistence.go:151
↓ 1 callersMethodFindByUsername
(username string)
pkg/repository/user.go:7
↓ 1 callersMethodHealthcheck
(c *gin.Context)
pkg/api/books.go:28
↓ 1 callersFunctionLogger
(logger *zap.Logger, collection *mongo.Collection)
pkg/middleware/logger.go:69
↓ 1 callersFunctionNewRedisClient
NewRedisClient builds a go-redis client from environment variables. See redisOptionsFromEnv for supported keys and defaults.
pkg/cache/cache.go:33
↓ 1 callersFunctionNewRouter
NewRouter builds the Gin engine with middleware, Swagger, and API routes.
pkg/api/router.go:26
↓ 1 callersMethodPatchBook
(c *gin.Context)
pkg/api/books.go:33
↓ 1 callersMethodPatchFields
(id uint, title, author *string)
pkg/repository/book.go:13
↓ 1 callersFunctionRateLimiter
(r rate.Limit, b int)
pkg/middleware/rate_limit.go:11
next →1–100 of 337, ranked by callers