(search dto.SearchForTree)
| 161 | } |
| 162 | |
| 163 | func (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 | |
| 193 | func (u *HostService) GetHostByID(id uint) (*dto.HostInfo, error) { |
| 194 | var item dto.HostInfo |
nothing calls this directly
no test coverage detected