ThingsPanel / thingspanel-backend-community

The plug-in IoT platform developed by Go language has high performance, low entry and easy expansion. Support MQTT, Modbus multi protocol, multi type device access and visualization, automation, alarm, rule engine and other functions.

Home Page:http://thingspanel.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

这些地方为什么不用单例呢?

sllt opened this issue · comments

像这些地方:

https://github.com/ThingsPanel/ThingsPanel-Go/blob/aae1cfbff9c2cc8a6fa57f3f42b64c03d8586be9/controllers/customer.go#L60

https://github.com/ThingsPanel/ThingsPanel-Go/blob/aae1cfbff9c2cc8a6fa57f3f42b64c03d8586be9/controllers/customer.go#L91

https://github.com/ThingsPanel/ThingsPanel-Go/blob/aae1cfbff9c2cc8a6fa57f3f42b64c03d8586be9/controllers/customer.go#L174

提供一种重构思路:

var Customer = new(customerService)

type customerService struct {}

func (c *customerService) Paginate(name string, offset int, pageSize int) ([]models.Customer, int64) {
}

....

调用:

service.Customer.Paginate(your params...)

感谢,多租户重构时候会参考您的意见