Refactor database interface to use *sql.DB directly
Simplified the database layer by removing custom interface wrappers and using standard library *sql.DB and *sql.Tx types directly. Changes: - Removed DBConnection and DBTransaction interfaces from database.go - Removed NewDBConnection() wrapper function - Updated TokenGenerator to use *sql.DB instead of DBConnection - Updated all validation and revocation methods to accept *sql.Tx - Updated TableManager to work with *sql.DB directly - Updated all tests to use db.Begin() instead of custom wrappers - Fixed GeneratorConfig.DB field (was DBConn) - Updated documentation in doc.go with correct API usage Benefits: - Simpler API with fewer abstractions - Works directly with database/sql standard library - Compatible with GORM (via gormDB.DB()) and Bun (share same *sql.DB) - Easier to understand and maintain - No unnecessary wrapper layers Breaking changes: - GeneratorConfig.DBConn renamed to GeneratorConfig.DB - Removed NewDBConnection() function - pass *sql.DB directly - ValidateAccess/ValidateRefresh now accept *sql.Tx instead of DBTransaction - Token.Revoke/CheckNotRevoked now accept *sql.Tx instead of DBTransaction 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,7 @@ func (server *Server) AddMiddleware(middleware ...Middleware) error {
|
||||
}
|
||||
|
||||
// RUN GZIP
|
||||
if server.gzip {
|
||||
if server.GZIP {
|
||||
server.server.Handler = addgzip(server.server.Handler)
|
||||
}
|
||||
// RUN TIMER MIDDLEWARE LAST
|
||||
@@ -35,6 +35,11 @@ func (server *Server) AddMiddleware(middleware ...Middleware) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewMiddleware returns a new Middleware for the server.
|
||||
// A MiddlewareFunc is a function that takes in a http.ResponseWriter and http.Request,
|
||||
// and returns a new request and optional HWSError.
|
||||
// If a HWSError is returned, server.ThrowError will be called.
|
||||
// If HWSError.RenderErrorPage is true, the request chain will be terminated and the error page rendered
|
||||
func (server *Server) NewMiddleware(
|
||||
middlewareFunc MiddlewareFunc,
|
||||
) Middleware {
|
||||
@@ -42,8 +47,10 @@ func (server *Server) NewMiddleware(
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
newReq, herr := middlewareFunc(w, r)
|
||||
if herr != nil {
|
||||
server.ThrowError(w, r, herr)
|
||||
return
|
||||
server.ThrowError(w, r, *herr)
|
||||
if herr.RenderErrorPage {
|
||||
return
|
||||
}
|
||||
}
|
||||
next.ServeHTTP(w, newReq)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user