Commit 004422b4 by huangchengyi

Merge branch 'master' of http://119.23.72.7/mushishixian/search_server

# Conflicts:
#	boot/app.go
#	controller/course_controller.go
#	controller/course_topic_controller.go
#	controller/mouser_controller.go
#	service/bom_service.go
parents ec807e10 f2b8edb8
......@@ -4,18 +4,27 @@ import (
"search_server/pkg/config"
"search_server/pkg/gredis"
"search_server/pkg/logger"
<<<<<<< HEAD
"search_server/pkg/mongo"
"search_server/pkg/mysql"
=======
>>>>>>> f2b8edb8d28bbb6afad6bbeb1baddb7f7d245e57
)
func Boot(configPath string) (err error) {
if err = config.SetUp(configPath); err != nil {
panic(err)
}
<<<<<<< HEAD
if err = mysql.Setup(); err != nil {
panic(err)
return
}
=======
//if err = mysql.Setup(); err != nil {
// return
//}
>>>>>>> f2b8edb8d28bbb6afad6bbeb1baddb7f7d245e57
if err = gredis.Setup(); err != nil {
panic(err)
return
......
package controller
import (
"github.com/gin-gonic/gin"
"search_server/framework/gin_"
"search_server/protopb/course"
"search_server/service"
)
func Init2() {
courseService := service.NewCourseServiceImpl()
gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()).
WithMiddleware(Cors_Middleware()).
WithEndpoint(Courselist_Endpoint(courseService)).
WithRequest(Courselist_Request()).
WithResponse(Course_Response()).Build("/course", "GET")
gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()).
WithEndpoint(Coursedetail_Endpoint(courseService)).
WithRequest(Coursedetail_Request()).
WithResponse(Course_Response()).Build("/detail/:course_id", "GET")
}
//详细相关
func Coursedetail_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp := &course.DetailResponse{Course: new(course.CourseModel), Counts: make([]*course.CourseCounts, 0)}
err = c.GetDetail(context, request.(*course.DetailRequest), rsp)
return rsp, err
}
}
//这个函数的作用是怎么处理请求
func Coursedetail_Request() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) {
bReq := &course.DetailRequest{}
err := context.BindUri(bReq)
if err != nil {
return nil, err
}
err = context.BindHeader(bReq)
if err != nil {
return nil, err
}
return bReq, nil
}
}
//获取列表相关
func Courselist_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp := &course.ListResponse{}
err = c.ListForTop(context, request.(*course.ListRequest), rsp)
return rsp, err
}
}
//这个函数的作用是怎么处理请求
func Courselist_Request() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) {
bReq := &course.ListRequest{}
err := context.BindQuery(bReq) //使用的是query 参数
if err != nil {
return nil, err
}
return bReq, nil
}
}
//这个函数作用是:怎么处理响应结果
func Course_Response() gin_.DecodeResponseFunc {
return func(context *gin.Context, res interface{}) error {
context.JSON(200, res)
return nil
}
}
package controller
import (
"github.com/gin-gonic/gin"
"search_server/framework/gin_"
"search_server/protopb/course"
"search_server/service"
)
func Init() {
courseService:=service.NewCourseTopicServiceImpl()
gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()).
WithEndpoint(CourseTopicList_Endpoint(courseService)).
WithRequest(CourseTopicList_Request()).
WithResponse(Course_Response()).Build("/topic/:cid","GET")
}
func CourseTopicList_Endpoint(c *service.CourseTopicServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp:=&course.TopicResponse{Result:make([]*course.CourseTopic,0)}
err=c.GetTopic(context,request.(*course.TopicRequest),rsp)
return rsp,err
}
}
//这个函数的作用是怎么处理请求
func CourseTopicList_Request() gin_.EncodeRequestFunc{
return func(context *gin.Context) (i interface{}, e error) {
bReq:=&course.TopicRequest{}
err:=context.BindUri(bReq) //使用的是query 参数
if err!=nil{
return nil,err
}
return bReq,nil
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ import (
"github.com/gin-gonic/gin"
"net/http"
"search_server/framework/gin_"
"search_server/pkg/config"
)
//放 通用中间件
......@@ -22,14 +21,14 @@ func Cors_Middleware() gin_.Middleware {
return func(next gin_.Endpoint) gin_.Endpoint {
return func(c *gin.Context, request interface{}) (response interface{}, err error) {
method := c.Request.Method
corsDomains := config.Get("web.cors.domain").Strings(",")
for _, domain := range corsDomains {
c.Header("Access-Control-Allow-Origin", domain)
}
//corsDomains := config.Get("web.cors.domain").Strings(",")
//for _, domain := range corsDomains {
// c.Header("Access-Control-Allow-Origin", domain)
//}
c.Header("Access-Control-Allow-Origin", "https://bom.ichunt.com")
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
//c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
//c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
//c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
//放行所有OPTIONS方法
......
package controller
import (
"github.com/gin-gonic/gin"
"search_server/framework/gin_"
"search_server/protopb/mouser"
"search_server/service"
)
func Init3() {
MouserService := service.NewMouserServiceImpl()
gin_.NewBuilder().WithService(MouserService).
WithEndpoint(MouserGetData(MouserService)).
WithRequest(MouserRequest()).
WithResponse(MouserResponse()).Build("/search/mouser/test", "POST")
}
//处理请求
func MouserGetData(c *service.MouserServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp := &mouser.MouserResponse{}
err = c.MouserGetData(context, request.(*mouser.MouserRequest), rsp)
return rsp, err
}
}
//接收请求
func MouserRequest() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) {
bReq := &mouser.MouserRequest{}
err := context.BindQuery(bReq) //使用的是query 参数
bReq.GoodsName, _ = context.GetPostForm("goods_name")
if err != nil {
return nil, err
}
return bReq, nil
}
}
//响应请求
func MouserResponse() gin_.DecodeResponseFunc {
return func(context *gin.Context, res interface{}) error {
context.JSON(200, res)
return nil
}
}
......@@ -167,8 +167,12 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool)
}
source := elastic.NewSearchSource().Query(query)
source.From(0)
<<<<<<< HEAD
source.Size(30)
=======
source.Size(50)
>>>>>>> f2b8edb8d28bbb6afad6bbeb1baddb7f7d245e57
source.Sort("_score", false).Sort("sort", false).Sort("single_price", true)
queryRequest := elastic.NewSearchRequest().Source(source)
result, _ = queryRequest.Body()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment