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) {
|
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
|
return nil, err
|
||||||
} else if foundPost != nil {
|
}
|
||||||
|
if foundPost != nil {
|
||||||
return foundPost, nil
|
return foundPost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ func GetMailBox(email string) (results JSONMessageHeaderInbucket, err error) {
|
|||||||
return record, nil
|
return record, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err error) {
|
func GetMessageFromMailbox(email, id string) (JSONMessageInbucket, error) {
|
||||||
|
|
||||||
parsedEmail := ParseEmail(email)
|
parsedEmail := ParseEmail(email)
|
||||||
|
|
||||||
var record JSONMessageInbucket
|
var record JSONMessageInbucket
|
||||||
@@ -102,17 +101,20 @@ func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err e
|
|||||||
}
|
}
|
||||||
defer emailResponse.Body.Close()
|
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
|
// download attachments
|
||||||
if record.Attachments != nil && len(record.Attachments) > 0 {
|
if record.Attachments != nil && len(record.Attachments) > 0 {
|
||||||
for i := range record.Attachments {
|
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
|
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 != "" {
|
if hostname != "" {
|
||||||
err := c.Hello(hostname)
|
err = c.Hello(hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Failed to to set the HELO to SMTP server %v", err))
|
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)
|
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)
|
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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
out := make(map[string]interface{}, len(in))
|
fixCaseOut := make(map[string]interface{}, len(in))
|
||||||
|
|
||||||
for i := 0; i < t.NumField(); i++ {
|
for i := 0; i < t.NumField(); i++ {
|
||||||
field := t.Field(i)
|
field := t.Field(i)
|
||||||
@@ -316,14 +316,14 @@ func fixEnvSettingsCase(in map[string]interface{}) (out map[string]interface{},
|
|||||||
key := field.Name
|
key := field.Name
|
||||||
if value, ok := in[strings.ToLower(key)]; ok {
|
if value, ok := in[strings.ToLower(key)]; ok {
|
||||||
if valueAsMap, ok := value.(map[string]interface{}); ok {
|
if valueAsMap, ok := value.(map[string]interface{}); ok {
|
||||||
out[key] = fixCase(valueAsMap, field.Type)
|
fixCaseOut[key] = fixCase(valueAsMap, field.Type)
|
||||||
} else {
|
} else {
|
||||||
out[key] = value
|
fixCaseOut[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return fixCaseOut
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fixCase(in, reflect.TypeOf(model.Config{}))
|
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()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
// Check for existing item
|
// Check for existing item
|
||||||
if value, ok := c.getValue(key); ok {
|
if actualValue, ok := c.getValue(key); ok {
|
||||||
return value, true
|
return actualValue, true
|
||||||
}
|
}
|
||||||
|
|
||||||
c.add(key, value, ttl)
|
c.add(key, value, ttl)
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti
|
|||||||
didAdd := false
|
didAdd := false
|
||||||
for i := lastMatchIndex; i >= 0; i-- {
|
for i := lastMatchIndex; i >= 0; i-- {
|
||||||
if container, ok := openBlocks[i].(ContainerBlock); ok {
|
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)
|
closeBlocks(openBlocks[i+1:], &referenceDefinitions)
|
||||||
openBlocks = openBlocks[:i+1]
|
openBlocks = openBlocks[:i+1]
|
||||||
openBlocks = append(openBlocks, newBlocks...)
|
openBlocks = append(openBlocks, addedBlocks...)
|
||||||
didAdd = true
|
didAdd = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,8 +398,8 @@ func (p *inlineParser) lookForLinkOrImage() {
|
|||||||
p.inlines = append(p.inlines[:d.TextNode], inline)
|
p.inlines = append(p.inlines[:d.TextNode], inline)
|
||||||
} else {
|
} else {
|
||||||
p.inlines = append(p.inlines[:d.TextNode], inline)
|
p.inlines = append(p.inlines[:d.TextNode], inline)
|
||||||
for element := element.Prev(); element != nil; element = element.Prev() {
|
for inlineElement := element.Prev(); inlineElement != nil; inlineElement = inlineElement.Prev() {
|
||||||
if d := element.Value.(*delimiter); d.Type == linkOpeningDelimiter {
|
if d := inlineElement.Value.(*delimiter); d.Type == linkOpeningDelimiter {
|
||||||
d.IsInactive = true
|
d.IsInactive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user