Explorar o código

gps定位时空指针的问题

luoyangwei hai 1 ano
pai
achega
e19dbfad7f

+ 1 - 1
cmd/wire/wire_gen.go

@@ -23,7 +23,7 @@ func NewWire(viperViper *viper.Viper) (*server.ExtServer, error) {
 	mapLocationModel := model.NewMapLocationModel(benewDB)
 	locationService := service.NewLocationService(viperViper, mapLocationModel)
 	aMapService := service.NewAMapService(viperViper, mapLocationModel, locationService)
-	gpsService := service.NewGpsService(viperViper, mapLocationModel)
+	gpsService := service.NewGpsService(viperViper, mapLocationModel, locationService)
 	locationHeader := handler.NewLocationHeader(handlerHandler, aMapService, gpsService)
 	whiteIplistModel := model.NewWhiteIplistModel(benewDB)
 	whiteIplistService := service.NewWhiteIplistService(whiteIplistModel)

+ 3 - 2
internal/handler/location_header.go

@@ -31,14 +31,15 @@ func NewLocationHeader(
 }
 
 func (h *LocationHeader) Post(c fiber.Ctx) error {
+	log := log.With().Str("requestId", requestid.FromContext(c)).Logger()
+
 	var request v1.PostLocationRequest
 	if err := c.Bind().Body(&request); err != nil {
+		log.Error().Err(err).Msg("绑定请求体失败")
 		return fiber.ErrBadRequest
 	}
 
-	log := log.With().Str("requestId", requestid.FromContext(c)).Logger()
 	log.Info().Any("request", request).Int32("accessType", request.AccessType).Msg("正在定位")
-
 	if request.AccessType == gpcLocationType {
 		if err := h.gpsService.Request(h.WrapFiberContext(c), &request); err != nil {
 			return err

+ 2 - 1
internal/service/gps_service.go

@@ -19,10 +19,11 @@ type GpsService struct {
 	locationService  *LocationService
 }
 
-func NewGpsService(conf *viper.Viper, mapLocationModel *model.MapLocationModel) *GpsService {
+func NewGpsService(conf *viper.Viper, mapLocationModel *model.MapLocationModel, locationService *LocationService) *GpsService {
 	return &GpsService{
 		conf:             conf,
 		mapLocationModel: mapLocationModel,
+		locationService:  locationService,
 	}
 }