This commit is contained in:
2025-10-24 21:44:15 +08:00
parent 2f56813874
commit 289812aac3
18 changed files with 576 additions and 100 deletions

View File

@@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
}

View File

@@ -0,0 +1,29 @@
package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
// Get presigned URL for file download
func DownloadPresignedURLHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DownloadPresignedURLReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewDownloadPresignedURLLogic(r.Context(), svcCtx)
resp, err := l.DownloadPresignedURL(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,29 @@
package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
// Ping the server to check if it's alive
func pingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PingReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewPingLogic(r.Context(), svcCtx)
resp, err := l.Ping(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,38 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.8.4
package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
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.WithPrefix("/api/blog"),
)
}

View File

@@ -0,0 +1,29 @@
package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/Blog/app/internal/logic"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
// Get presigned URL for file upload
func UploadPresignedURLHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UploadPresignedURLReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewUploadPresignedURLLogic(r.Context(), svcCtx)
resp, err := l.UploadPresignedURL(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,31 @@
package logic
import (
"context"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DownloadPresignedURLLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Get presigned URL for file download
func NewDownloadPresignedURLLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadPresignedURLLogic {
return &DownloadPresignedURLLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DownloadPresignedURLLogic) DownloadPresignedURL(req *types.DownloadPresignedURLReq) (resp *types.DownloadPresignedURLResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,31 @@
package logic
import (
"context"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Ping the server to check if it's alive
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PingLogic) Ping(req *types.PingReq) (resp *types.PingResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,31 @@
package logic
import (
"context"
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
"git.cialloo.com/CiallooWeb/Blog/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UploadPresignedURLLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Get presigned URL for file upload
func NewUploadPresignedURLLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadPresignedURLLogic {
return &UploadPresignedURLLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UploadPresignedURLLogic) UploadPresignedURL(req *types.UploadPresignedURLReq) (resp *types.UploadPresignedURLResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,15 @@
package svc
import (
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
)
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

View File

@@ -0,0 +1,30 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.8.4
package types
type DownloadPresignedURLReq struct {
File_key string `json:"file_key"` // Key to identify the file to download
}
type DownloadPresignedURLResp struct {
Url string `json:"url"` // Presigned URL for download
Expire_at int64 `json:"expire_at"` // Expiration timestamp
}
type PingReq struct {
}
type PingResp struct {
Ok bool `json:"ok"`
}
type UploadPresignedURLReq struct {
File_name string `json:"file_name"` // Original file name
}
type UploadPresignedURLResp struct {
Url string `json:"url"` // Presigned URL for upload
File_key string `json:"file_key"` // Key to identify the uploaded file
Expire_at int64 `json:"expire_at"` // Expiration timestamp
}