update
This commit is contained in:
@@ -37,6 +37,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
@server (
|
@server (
|
||||||
|
middleware: SuperAdminAuthMiddleware
|
||||||
prefix: /api/blog
|
prefix: /api/blog
|
||||||
)
|
)
|
||||||
service Blog {
|
service Blog {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.SuperAdminAuthMiddleware},
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
// Get presigned URL for file download
|
// Get presigned URL for file download
|
||||||
@@ -32,7 +34,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/ping",
|
Path: "/ping",
|
||||||
Handler: pingHandler(serverCtx),
|
Handler: pingHandler(serverCtx),
|
||||||
},
|
},
|
||||||
},
|
}...,
|
||||||
|
),
|
||||||
rest.WithPrefix("/api/blog"),
|
rest.WithPrefix("/api/blog"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
24
app/internal/middleware/superadminauthmiddleware.go
Normal file
24
app/internal/middleware/superadminauthmiddleware.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,15 +5,20 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
|
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
|
||||||
|
"git.cialloo.com/CiallooWeb/Blog/app/internal/middleware"
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
|
|
||||||
|
SuperAdminAuthMiddleware rest.Middleware
|
||||||
|
|
||||||
S3Client *s3.Client
|
S3Client *s3.Client
|
||||||
DB *sql.DB
|
DB *sql.DB
|
||||||
}
|
}
|
||||||
@@ -21,6 +26,9 @@ type ServiceContext struct {
|
|||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
|
||||||
|
SuperAdminAuthMiddleware: middleware.NewSuperAdminAuthMiddleware(c).Handle,
|
||||||
|
|
||||||
S3Client: initS3Client(c.S3),
|
S3Client: initS3Client(c.S3),
|
||||||
DB: initDatabase(c.Database),
|
DB: initDatabase(c.Database),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user