MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Page

Method Page

agent/app/service/container.go:110–151  ·  view source on GitHub ↗
(req dto.PageContainer)

Source from the content-addressed store, hash-verified

108}
109
110func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, error) {
111 client, err := docker.NewDockerClient()
112 if err != nil {
113 return 0, nil, err
114 }
115 defer func() { _ = client.Close() }()
116 options := container.ListOptions{All: true}
117 if len(req.Filters) != 0 {
118 options.Filters = filters.NewArgs()
119 options.Filters.Add("label", req.Filters)
120 }
121 containers, err := client.ContainerList(context.Background(), options)
122 if err != nil {
123 return 0, nil, err
124 }
125 records := searchWithFilter(req, containers)
126
127 var backData []dto.ContainerInfo
128 total, start, end := len(records), (req.Page-1)*req.PageSize, req.Page*req.PageSize
129 if start > total {
130 backData = make([]dto.ContainerInfo, 0)
131 } else {
132 if end >= total {
133 end = total
134 }
135 backData = records[start:end]
136 }
137
138 for i := 0; i < len(backData); i++ {
139 install, _ := appInstallRepo.GetFirst(appInstallRepo.WithContainerName(backData[i].Name))
140 if install.ID > 0 {
141 backData[i].AppInstallName = install.Name
142 backData[i].AppName = install.App.Name
143 websites, _ := websiteRepo.GetBy(websiteRepo.WithAppInstallId(install.ID))
144 for _, website := range websites {
145 backData[i].Websites = append(backData[i].Websites, website.PrimaryDomain)
146 }
147 }
148 }
149
150 return int64(total), backData, nil
151}
152
153func (u *ContainerService) List() []dto.ContainerOptions {
154 var options []dto.ContainerOptions

Callers

nothing calls this directly

Calls 6

searchWithFilterFunction · 0.85
CloseMethod · 0.65
GetFirstMethod · 0.65
WithContainerNameMethod · 0.65
GetByMethod · 0.65
WithAppInstallIdMethod · 0.65

Tested by

no test coverage detected