Fix shadowed variables in various places: Part 2 of 2 (#10176)
This PR fixes shadowed variables in the following packages: - `app` - `utils` - `utils/markdown` - `services/mailservice`
Этот коммит содержится в:
@@ -134,9 +134,11 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
|
||||
}
|
||||
|
||||
func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (savedPost *model.Post, err *model.AppError) {
|
||||
if foundPost, err := a.deduplicateCreatePost(post); err != nil {
|
||||
foundPost, err := a.deduplicateCreatePost(post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if foundPost != nil {
|
||||
}
|
||||
if foundPost != nil {
|
||||
return foundPost, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,7 @@ func GetMailBox(email string) (results JSONMessageHeaderInbucket, err error) {
|
||||
return record, nil
|
||||
}
|
||||
|
||||
func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err error) {
|
||||
|
||||
func GetMessageFromMailbox(email, id string) (JSONMessageInbucket, error) {
|
||||
parsedEmail := ParseEmail(email)
|
||||
|
||||
var record JSONMessageInbucket
|
||||
@@ -102,17 +101,20 @@ func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err e
|
||||
}
|
||||
defer emailResponse.Body.Close()
|
||||
|
||||
err = json.NewDecoder(emailResponse.Body).Decode(&record)
|
||||
if err = json.NewDecoder(emailResponse.Body).Decode(&record); err != nil {
|
||||
return record, err
|
||||
}
|
||||
|
||||
// download attachments
|
||||
if record.Attachments != nil && len(record.Attachments) > 0 {
|
||||
for i := range record.Attachments {
|
||||
if bytes, err := downloadAttachment(record.Attachments[i].DownloadLink); err != nil {
|
||||
var bytes []byte
|
||||
bytes, err = downloadAttachment(record.Attachments[i].DownloadLink)
|
||||
if err != nil {
|
||||
return record, err
|
||||
} else {
|
||||
record.Attachments[i].Bytes = make([]byte, len(bytes))
|
||||
copy(record.Attachments[i].Bytes, bytes)
|
||||
}
|
||||
record.Attachments[i].Bytes = make([]byte, len(bytes))
|
||||
copy(record.Attachments[i].Bytes, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ func NewSMTPClientAdvanced(conn net.Conn, hostname string, connectionInfo *SmtpC
|
||||
}
|
||||
|
||||
if hostname != "" {
|
||||
err := c.Hello(hostname)
|
||||
err = c.Hello(hostname)
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprintf("Failed to to set the HELO to SMTP server %v", err))
|
||||
return nil, model.NewAppError("SendMail", "utils.mail.connect_smtp.helo.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -273,11 +273,11 @@ func SendMail(c *smtp.Client, mimeTo, smtpTo string, from mail.Address, subject,
|
||||
}))
|
||||
}
|
||||
|
||||
if err := c.Mail(from.Address); err != nil {
|
||||
if err = c.Mail(from.Address); err != nil {
|
||||
return model.NewAppError("SendMail", "utils.mail.send_mail.from_address.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := c.Rcpt(smtpTo); err != nil {
|
||||
if err = c.Rcpt(smtpTo); err != nil {
|
||||
return model.NewAppError("SendMail", "utils.mail.send_mail.to_address.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ func fixEnvSettingsCase(in map[string]interface{}) (out map[string]interface{},
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make(map[string]interface{}, len(in))
|
||||
fixCaseOut := make(map[string]interface{}, len(in))
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
@@ -316,14 +316,14 @@ func fixEnvSettingsCase(in map[string]interface{}) (out map[string]interface{},
|
||||
key := field.Name
|
||||
if value, ok := in[strings.ToLower(key)]; ok {
|
||||
if valueAsMap, ok := value.(map[string]interface{}); ok {
|
||||
out[key] = fixCase(valueAsMap, field.Type)
|
||||
fixCaseOut[key] = fixCase(valueAsMap, field.Type)
|
||||
} else {
|
||||
out[key] = value
|
||||
fixCaseOut[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
return fixCaseOut
|
||||
}
|
||||
|
||||
out = fixCase(in, reflect.TypeOf(model.Config{}))
|
||||
|
||||
@@ -140,8 +140,8 @@ func (c *Cache) GetOrAdd(key, value interface{}, ttl time.Duration) (actual inte
|
||||
defer c.lock.Unlock()
|
||||
|
||||
// Check for existing item
|
||||
if value, ok := c.getValue(key); ok {
|
||||
return value, true
|
||||
if actualValue, ok := c.getValue(key); ok {
|
||||
return actualValue, true
|
||||
}
|
||||
|
||||
c.add(key, value, ttl)
|
||||
|
||||
@@ -77,10 +77,10 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti
|
||||
didAdd := false
|
||||
for i := lastMatchIndex; i >= 0; i-- {
|
||||
if container, ok := openBlocks[i].(ContainerBlock); ok {
|
||||
if newBlocks := container.AddChild(newBlocks); newBlocks != nil {
|
||||
if addedBlocks := container.AddChild(newBlocks); addedBlocks != nil {
|
||||
closeBlocks(openBlocks[i+1:], &referenceDefinitions)
|
||||
openBlocks = openBlocks[:i+1]
|
||||
openBlocks = append(openBlocks, newBlocks...)
|
||||
openBlocks = append(openBlocks, addedBlocks...)
|
||||
didAdd = true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -398,8 +398,8 @@ func (p *inlineParser) lookForLinkOrImage() {
|
||||
p.inlines = append(p.inlines[:d.TextNode], inline)
|
||||
} else {
|
||||
p.inlines = append(p.inlines[:d.TextNode], inline)
|
||||
for element := element.Prev(); element != nil; element = element.Prev() {
|
||||
if d := element.Value.(*delimiter); d.Type == linkOpeningDelimiter {
|
||||
for inlineElement := element.Prev(); inlineElement != nil; inlineElement = inlineElement.Prev() {
|
||||
if d := inlineElement.Value.(*delimiter); d.Type == linkOpeningDelimiter {
|
||||
d.IsInactive = true
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user