update
This commit is contained in:
31
app/blog.go
Normal file
31
app/blog.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/config"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/handler"
|
||||
"git.cialloo.com/CiallooWeb/Blog/app/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/blog.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
3
app/etc/blog.yaml
Normal file
3
app/etc/blog.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
Name: Blog
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
7
app/internal/config/config.go
Normal file
7
app/internal/config/config.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
}
|
||||
29
app/internal/handler/downloadpresignedurlhandler.go
Normal file
29
app/internal/handler/downloadpresignedurlhandler.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
app/internal/handler/pinghandler.go
Normal file
29
app/internal/handler/pinghandler.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
38
app/internal/handler/routes.go
Normal file
38
app/internal/handler/routes.go
Normal 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"),
|
||||
)
|
||||
}
|
||||
29
app/internal/handler/uploadpresignedurlhandler.go
Normal file
29
app/internal/handler/uploadpresignedurlhandler.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
app/internal/logic/downloadpresignedurllogic.go
Normal file
31
app/internal/logic/downloadpresignedurllogic.go
Normal 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
|
||||
}
|
||||
31
app/internal/logic/pinglogic.go
Normal file
31
app/internal/logic/pinglogic.go
Normal 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
|
||||
}
|
||||
31
app/internal/logic/uploadpresignedurllogic.go
Normal file
31
app/internal/logic/uploadpresignedurllogic.go
Normal 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
|
||||
}
|
||||
15
app/internal/svc/servicecontext.go
Normal file
15
app/internal/svc/servicecontext.go
Normal 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,
|
||||
}
|
||||
}
|
||||
30
app/internal/types/types.go
Normal file
30
app/internal/types/types.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user