41 lines
1.7 KiB
Go
41 lines
1.7 KiB
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"bj_power_workstation/internal/auth"
|
||
|
|
"bj_power_workstation/internal/svc"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/rest"
|
||
|
|
)
|
||
|
|
|
||
|
|
func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||
|
|
// 免鉴权:健康检查 / 登录 / 工位配置
|
||
|
|
server.AddRoutes(
|
||
|
|
[]rest.Route{
|
||
|
|
{Method: http.MethodGet, Path: "/api/health", Handler: healthHandler(ctx)},
|
||
|
|
{Method: http.MethodPost, Path: "/api/auth/login", Handler: loginHandler(ctx)},
|
||
|
|
{Method: http.MethodGet, Path: "/api/config", Handler: configHandler(ctx)},
|
||
|
|
// 前端静态托管
|
||
|
|
{Method: http.MethodGet, Path: "/", Handler: indexHandler(ctx.WebFS)},
|
||
|
|
{Method: http.MethodGet, Path: "/assets/:file", Handler: assetHandler(ctx.WebFS)},
|
||
|
|
},
|
||
|
|
)
|
||
|
|
|
||
|
|
// 登录鉴权中间件:白名单 /api/health、/api/auth/login、/api/config、/pdfopen/*
|
||
|
|
server.Use(auth.Interceptor(ctx.Config.Auth.AccessSecret, ctx.Config.Auth.AccessExpire))
|
||
|
|
|
||
|
|
// 业务接口(均需登录 JWT;PDF 代理除外——原样转发文件流)
|
||
|
|
server.AddRoutes(
|
||
|
|
[]rest.Route{
|
||
|
|
{Method: http.MethodGet, Path: "/api/task/current", Handler: taskCurrentHandler(ctx)},
|
||
|
|
{Method: http.MethodGet, Path: "/api/pdf", Handler: pdfQueryHandler(ctx)},
|
||
|
|
{Method: http.MethodGet, Path: "/pdfopen/:name", Handler: pdfOpenHandler(ctx)},
|
||
|
|
{Method: http.MethodGet, Path: "/api/tightening/list", Handler: tighteningListHandler(ctx)},
|
||
|
|
{Method: http.MethodPost, Path: "/api/report/process-done", Handler: processDoneHandler(ctx)},
|
||
|
|
{Method: http.MethodPost, Path: "/api/report/temp-store", Handler: tempStoreHandler(ctx)},
|
||
|
|
{Method: http.MethodPost, Path: "/api/sync/flush", Handler: syncFlushHandler(ctx)},
|
||
|
|
{Method: http.MethodGet, Path: "/api/sync/stats", Handler: syncStatsHandler(ctx)},
|
||
|
|
},
|
||
|
|
)
|
||
|
|
}
|