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

Method SearchForTree

agent/app/service/host.go:163–191  ·  view source on GitHub ↗
(search dto.SearchForTree)

Source from the content-addressed store, hash-verified

161}
162
163func (u *HostService) SearchForTree(search dto.SearchForTree) ([]dto.HostTree, error) {
164 hosts, err := hostRepo.GetList(hostRepo.WithByInfo(search.Info))
165 if err != nil {
166 return nil, err
167 }
168 groups, err := groupRepo.GetList(repo.WithByType("host"))
169 if err != nil {
170 return nil, err
171 }
172 var datas []dto.HostTree
173 for _, group := range groups {
174 var data dto.HostTree
175 data.ID = group.ID + 10000
176 data.Label = group.Name
177 for _, host := range hosts {
178 label := fmt.Sprintf("%s@%s:%d", host.User, host.Addr, host.Port)
179 if len(host.Name) != 0 {
180 label = fmt.Sprintf("%s - %s@%s:%d", host.Name, host.User, host.Addr, host.Port)
181 }
182 if host.GroupID == group.ID {
183 data.Children = append(data.Children, dto.TreeChild{ID: host.ID, Label: label})
184 }
185 }
186 if len(data.Children) != 0 {
187 datas = append(datas, data)
188 }
189 }
190 return datas, err
191}
192
193func (u *HostService) GetHostByID(id uint) (*dto.HostInfo, error) {
194 var item dto.HostInfo

Callers

nothing calls this directly

Calls 3

GetListMethod · 0.65
WithByInfoMethod · 0.65
WithByTypeMethod · 0.65

Tested by

no test coverage detected