MCPcopy Index your code
hub / github.com/apache/answer / parseUserID

Method parseUserID

internal/service/search_parser/search_parser.go:155–177  ·  view source on GitHub ↗

parseUserID return user id or current login user id

(ctx context.Context, query *string, currentUserID string)

Source from the content-addressed store, hash-verified

153
154// parseUserID return user id or current login user id
155func (sp *SearchParser) parseUserID(ctx context.Context, query *string, currentUserID string) (userID string) {
156 var (
157 exprUsername = `user:(\S+)`
158 exprMe = "user:me"
159 q = *query
160 )
161
162 re := regexp.MustCompile(exprUsername)
163 res := re.FindStringSubmatch(q)
164 if strings.Contains(q, exprMe) {
165 userID = currentUserID
166 q = strings.ReplaceAll(q, exprMe, "")
167 } else if len(res) > 1 {
168 name := res[1]
169 user, has, err := sp.userCommon.GetUserBasicInfoByUserName(ctx, name)
170 if err == nil && has {
171 userID = user.ID
172 q = re.ReplaceAllString(q, "")
173 }
174 }
175 *query = strings.TrimSpace(q)
176 return
177}
178
179// parseVotes return the votes of search query
180func (sp *SearchParser) parseVotes(query *string) (votes int) {

Callers 1

ParseStructureMethod · 0.95

Calls 1

Tested by

no test coverage detected