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

Method SearchWithPage

agent/app/service/host.go:114–161  ·  view source on GitHub ↗
(req dto.SearchPageWithGroup)

Source from the content-addressed store, hash-verified

112}
113
114func (u *HostService) SearchWithPage(req dto.SearchPageWithGroup) (int64, interface{}, error) {
115 var options []repo.DBOption
116 if len(req.Info) != 0 {
117 options = append(options, hostRepo.WithByInfo(req.Info))
118 }
119 if req.GroupID != 0 {
120 options = append(options, repo.WithByGroupID(req.GroupID))
121 }
122 total, hosts, err := hostRepo.Page(req.Page, req.PageSize, options...)
123 if err != nil {
124 return 0, nil, err
125 }
126 var dtoHosts []dto.HostInfo
127 for _, host := range hosts {
128 var item dto.HostInfo
129 if err := copier.Copy(&item, &host); err != nil {
130 return 0, nil, buserr.WithDetail("ErrStructTransform", err.Error(), nil)
131 }
132 group, _ := groupRepo.Get(repo.WithByID(host.GroupID))
133 item.GroupBelong = group.Name
134 if !item.RememberPassword {
135 item.Password = ""
136 item.PrivateKey = ""
137 item.PassPhrase = ""
138 } else {
139 if len(host.Password) != 0 {
140 item.Password, err = encrypt.StringDecrypt(host.Password)
141 if err != nil {
142 return 0, nil, err
143 }
144 }
145 if len(host.PrivateKey) != 0 {
146 item.PrivateKey, err = encrypt.StringDecrypt(host.PrivateKey)
147 if err != nil {
148 return 0, nil, err
149 }
150 }
151 if len(host.PassPhrase) != 0 {
152 item.PassPhrase, err = encrypt.StringDecrypt(host.PassPhrase)
153 if err != nil {
154 return 0, nil, err
155 }
156 }
157 }
158 dtoHosts = append(dtoHosts, item)
159 }
160 return total, dtoHosts, err
161}
162
163func (u *HostService) SearchForTree(search dto.SearchForTree) ([]dto.HostTree, error) {
164 hosts, err := hostRepo.GetList(hostRepo.WithByInfo(search.Info))

Callers

nothing calls this directly

Calls 6

CopyMethod · 0.80
WithByInfoMethod · 0.65
PageMethod · 0.65
GetMethod · 0.65
WithByIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected