This commit is contained in:
2025-10-25 08:18:18 +08:00
parent ec80aa92fa
commit 6b0a88ed4c
4 changed files with 59 additions and 23 deletions

View File

@@ -13,26 +13,29 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
// Get presigned URL for file download
Method: http.MethodPost,
Path: "/file/download",
Handler: DownloadPresignedURLHandler(serverCtx),
},
{
// Get presigned URL for file upload
Method: http.MethodPost,
Path: "/file/upload",
Handler: UploadPresignedURLHandler(serverCtx),
},
{
// Ping the server to check if it's alive
Method: http.MethodGet,
Path: "/ping",
Handler: pingHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SuperAdminAuthMiddleware},
[]rest.Route{
{
// Get presigned URL for file download
Method: http.MethodPost,
Path: "/file/download",
Handler: DownloadPresignedURLHandler(serverCtx),
},
{
// Get presigned URL for file upload
Method: http.MethodPost,
Path: "/file/upload",
Handler: UploadPresignedURLHandler(serverCtx),
},
{
// Ping the server to check if it's alive
Method: http.MethodGet,
Path: "/ping",
Handler: pingHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/blog"),
)
}

View File

@@ -0,0 +1,24 @@
package middleware
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
)
type SuperAdminAuthMiddleware struct {
Config config.Config
}
func NewSuperAdminAuthMiddleware(c config.Config) *SuperAdminAuthMiddleware {
return &SuperAdminAuthMiddleware{Config: c}
}
func (m *SuperAdminAuthMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO generate middleware implement function, delete after code implementation
// Passthrough to next handler if need
next(w, r)
}
}

View File

@@ -5,22 +5,30 @@ import (
"database/sql"
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
"git.cialloo.com/CiallooWeb/Blog/app/internal/middleware"
"github.com/aws/aws-sdk-go-v2/aws"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
_ "github.com/lib/pq"
"github.com/zeromicro/go-zero/rest"
)
type ServiceContext struct {
Config config.Config
Config config.Config
SuperAdminAuthMiddleware rest.Middleware
S3Client *s3.Client
DB *sql.DB
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
Config: c,
SuperAdminAuthMiddleware: middleware.NewSuperAdminAuthMiddleware(c).Handle,
S3Client: initS3Client(c.S3),
DB: initDatabase(c.Database),
}