- 创建头像上传API接口 (POST /api/v1/users/:id/avatar) - 实现完整的头像上传逻辑,包含权限验证和文件处理 - 添加头像图片处理功能,支持自动压缩和居中裁剪 - 完善静态文件服务,支持头像访问 - 创建完整的API测试用例 - 更新任务进度文档 任务11已完成,项目完成率提升至37.5%
42 lines
898 B
Go
42 lines
898 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"photography-backend/internal/config"
|
|
"photography-backend/internal/handler"
|
|
"photography-backend/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
var configFile = flag.String("f", "etc/photographyapi-api.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)
|
|
|
|
// 添加静态文件服务
|
|
server.AddRoute(rest.Route{
|
|
Method: http.MethodGet,
|
|
Path: "/uploads/*",
|
|
Handler: func(w http.ResponseWriter, r *http.Request) {
|
|
http.StripPrefix("/uploads/", http.FileServer(http.Dir("uploads"))).ServeHTTP(w, r)
|
|
},
|
|
})
|
|
|
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
server.Start()
|
|
}
|