我想知道这段代码中的模式和逻辑

时间:2016-02-07 19:15:33

标签: go

我是Go的新手所以我需要了解模式并理解此代码中的逻辑

首先: 在汽车模型文件夹中的.go文件名为car.go,但其结构为

并在控制器文件夹中有一个cars.go文件,如下所示

        List<Object> objects = Arrays
            .stream(objectArr)
            .map(this::fn)
            .filter(Objects::nonNull)
            .limit(2)
            .collect(toList());

并且在service文件夹中是carService.go文件,如下所示

type Car struct {
    Id        bson.ObjectId `bson:"_id"`
    Model     string        `bson:"model" form:"" json:"model" binding:"required"`
    Brand     string        `bson:"brand" form:"brand" json:"brand" binding:"required"`
    CreatedAt bson.MongoTimestamp
}

type CarController struct {
    carService *services.CarService
}

func (controller CarController) New() *CarController {
    controller.carService = services.CarService{}.New()

    return &controller
}

func (controller CarController) GetIndex(c *gin.Context) {
    carList := controller.carService.Find(&bson.M{})
    c.JSON(http.StatusOK, &carList)
    //fmt.Println(carList) }
}

我想知道这段代码中使用的模式我理解完整的逻辑和什么是*含义??

1 个答案:

答案 0 :(得分:2)

*是指针。

请停止您正在做的所有事情并采取行动tour