Files
hldrCenter/server/internal/social_service/handler/socialService/listsocialservicehandler.go
2025-10-29 11:44:33 +08:00

51 lines
1.3 KiB
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package socialService
import (
"fmt"
"net/http"
"github.com/JACKYMYPERSON/hldrCenter/config"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service/internal/logic/socialService"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service/internal/model"
"github.com/JACKYMYPERSON/hldrCenter/internal/social_service/internal/types"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/rest/httpx"
)
func ListSocialServiceHandler(cfg *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListSocialServiceReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
mysqlCfg := cfg.MySQL
dsn := fmt.Sprintf(
"%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=true&loc=Local",
mysqlCfg.Username,
mysqlCfg.Password,
mysqlCfg.Host,
mysqlCfg.Port,
mysqlCfg.Database,
mysqlCfg.Charset,
)
fmt.Println("接收到articlePost请求")
conn := sqlx.NewSqlConn("mysql", dsn)
meetingModel := model.NewSocialServiceModel(conn)
l := socialService.NewListSocialServiceLogic(r.Context(), cfg, meetingModel)
resp, err := l.ListSocialService(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}