Skip to content

Instantly share code, notes, and snippets.

View Renrensan's full-sized avatar

Pasha Renaisan Renrensan

View GitHub Profile
package auth
import (
"github.com/Renrensan/go-auth-demo/middleware"
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)
// RegisterAuthRoutes sets up authentication-related routes on the provided router group.
package auth
import (
"github.com/Renrensan/go-auth-demo/utils"
"github.com/gin-gonic/gin"
)
// AuthController is responsible for handling authentication-related HTTP requests.
// It communicates with the AuthService to process authentication logic.
type AuthController struct {
package auth
import (
"github.com/Renrensan/go-auth-demo/utils"
)
// AuthService contains the business logic for authentication operations.
type AuthService struct {
authRepository IAuthRepository // Repository for accessing data (e.g., user information)
}
package auth
import (
"context"
"errors"
"fmt"
"time"
"github.com/Renrensan/go-auth-demo/db"
"github.com/Renrensan/go-auth-demo/utils"
package auth
import (
"github.com/Renrensan/go-auth-demo/middleware"
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)
// RegisterAuthRoutes sets up authentication-related routes on the provided router group.
...
func (authController *AuthController) Protected(ctx *gin.Context) {
response := utils.NewHttpResponse(200, "Hello Protected", nil)
ctx.JSON(response.StatusCode, response)
}
package middleware
import (
"errors"
"fmt"
"os"
"strings"
"github.com/Renrensan/go-auth-demo/utils"
"github.com/gin-gonic/gin"
package auth
import (
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)
// RegisterAuthRoutes sets up authentication-related routes on the provided router group.
// It takes the Gin router group, GORM database connection, and Redis client as dependencies.
package auth
import (
"github.com/Renrensan/go-auth-demo/utils"
"github.com/gin-gonic/gin"
)
// AuthController is responsible for handling authentication-related HTTP requests.
// It communicates with the AuthService to process authentication logic.
type AuthController struct {
package auth
import (
"github.com/Renrensan/go-auth-demo/utils"
)
// AuthService contains the business logic for authentication operations.
type AuthService struct {
authRepository IAuthRepository // Repository for accessing data (e.g., user information)
}