From c5e8cb25caa39ed018ede5270e1566e8f7448396 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 30 Oct 2017 11:57:24 -0500 Subject: simplify things (#7735) --- model/authorize.go | 7 +------ model/client4.go | 2 +- model/config.go | 7 +------ model/config_test.go | 2 +- model/license.go | 12 ++---------- model/scheduled_task_test.go | 4 ++-- model/search_params.go | 14 ++------------ model/search_params_test.go | 12 ++++++------ model/status_test.go | 3 +-- model/utils.go | 6 +----- 10 files changed, 18 insertions(+), 51 deletions(-) (limited to 'model') diff --git a/model/authorize.go b/model/authorize.go index 0bce484c9..df07ff142 100644 --- a/model/authorize.go +++ b/model/authorize.go @@ -155,10 +155,5 @@ func AuthorizeRequestFromJson(data io.Reader) *AuthorizeRequest { } func (ad *AuthData) IsExpired() bool { - - if GetMillis() > ad.CreateAt+int64(ad.ExpiresIn*1000) { - return true - } - - return false + return GetMillis() > ad.CreateAt+int64(ad.ExpiresIn*1000) } diff --git a/model/client4.go b/model/client4.go index 1c20954d8..bcd41638b 100644 --- a/model/client4.go +++ b/model/client4.go @@ -44,7 +44,7 @@ func BuildErrorResponse(r *http.Response, err *AppError) *Response { header = r.Header } else { statusCode = 0 - header = make(http.Header, 0) + header = make(http.Header) } return &Response{ diff --git a/model/config.go b/model/config.go index 768009d94..41a5db8cd 100644 --- a/model/config.go +++ b/model/config.go @@ -850,12 +850,7 @@ func (o *Config) SetDefaults() { if o.EmailSettings.EnableSignInWithEmail == nil { o.EmailSettings.EnableSignInWithEmail = new(bool) - - if o.EmailSettings.EnableSignUpWithEmail == true { - *o.EmailSettings.EnableSignInWithEmail = true - } else { - *o.EmailSettings.EnableSignInWithEmail = false - } + *o.EmailSettings.EnableSignInWithEmail = o.EmailSettings.EnableSignUpWithEmail } if o.EmailSettings.EnableSignInWithUsername == nil { diff --git a/model/config_test.go b/model/config_test.go index f10e2d0cd..86958458c 100644 --- a/model/config_test.go +++ b/model/config_test.go @@ -29,7 +29,7 @@ func TestConfigDefaultFileSettingsS3SSE(t *testing.T) { c1 := Config{} c1.SetDefaults() - if *c1.FileSettings.AmazonS3SSE != false { + if *c1.FileSettings.AmazonS3SSE { t.Fatal("FileSettings.AmazonS3SSE should default to false") } } diff --git a/model/license.go b/model/license.go index a26babcd2..3e42a2343 100644 --- a/model/license.go +++ b/model/license.go @@ -155,19 +155,11 @@ func (f *Features) SetDefaults() { } func (l *License) IsExpired() bool { - now := GetMillis() - if l.ExpiresAt < now { - return true - } - return false + return l.ExpiresAt < GetMillis() } func (l *License) IsStarted() bool { - now := GetMillis() - if l.StartsAt < now { - return true - } - return false + return l.StartsAt < GetMillis() } func (l *License) ToJson() string { diff --git a/model/scheduled_task_test.go b/model/scheduled_task_test.go index 6ba8edaf9..5af43b1ef 100644 --- a/model/scheduled_task_test.go +++ b/model/scheduled_task_test.go @@ -36,7 +36,7 @@ func TestCreateTask(t *testing.T) { t.Fatal("Bad interval") } - if task.Recurring != false { + if task.Recurring { t.Fatal("should not reccur") } } @@ -75,7 +75,7 @@ func TestCreateRecurringTask(t *testing.T) { t.Fatal("Bad interval") } - if task.Recurring != true { + if !task.Recurring { t.Fatal("should reccur") } diff --git a/model/search_params.go b/model/search_params.go index 070ac6d24..2feea8da1 100644 --- a/model/search_params.go +++ b/model/search_params.go @@ -31,16 +31,6 @@ func (o *SearchParams) ToJson() string { var searchFlags = [...]string{"from", "channel", "in"} -func splitWordsNoQuotes(text string) []string { - words := []string{} - - for _, word := range strings.Fields(text) { - words = append(words, word) - } - - return words -} - func splitWords(text string) []string { words := []string{} @@ -55,14 +45,14 @@ func splitWords(text string) []string { foundQuote = false location = i + 1 } else { - words = append(words, splitWordsNoQuotes(text[location:i])...) + words = append(words, strings.Fields(text[location:i])...) foundQuote = true location = i } } } - words = append(words, splitWordsNoQuotes(text[location:])...) + words = append(words, strings.Fields(text[location:])...) return words } diff --git a/model/search_params_test.go b/model/search_params_test.go index 0e55c7ead..3de4e0b52 100644 --- a/model/search_params_test.go +++ b/model/search_params_test.go @@ -177,19 +177,19 @@ func TestParseSearchParams(t *testing.T) { t.Fatalf("Incorrect output from parse search params: %v", sp) } - if sp := ParseSearchParams("words words"); len(sp) != 1 || sp[0].Terms != "words words" || sp[0].IsHashtag != false || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { + if sp := ParseSearchParams("words words"); len(sp) != 1 || sp[0].Terms != "words words" || sp[0].IsHashtag || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp) } - if sp := ParseSearchParams("\"my stuff\""); len(sp) != 1 || sp[0].Terms != "\"my stuff\"" || sp[0].IsHashtag != false || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { + if sp := ParseSearchParams("\"my stuff\""); len(sp) != 1 || sp[0].Terms != "\"my stuff\"" || sp[0].IsHashtag || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp) } - if sp := ParseSearchParams("#words #words"); len(sp) != 1 || sp[0].Terms != "#words #words" || sp[0].IsHashtag != true || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { + if sp := ParseSearchParams("#words #words"); len(sp) != 1 || sp[0].Terms != "#words #words" || !sp[0].IsHashtag || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp) } - if sp := ParseSearchParams("#words words"); len(sp) != 2 || sp[1].Terms != "#words" || sp[1].IsHashtag != true || len(sp[1].InChannels) != 0 || len(sp[1].FromUsers) != 0 || sp[0].Terms != "words" || sp[0].IsHashtag != false || len(sp[0].InChannels) != 0 { + if sp := ParseSearchParams("#words words"); len(sp) != 2 || sp[1].Terms != "#words" || !sp[1].IsHashtag || len(sp[1].InChannels) != 0 || len(sp[1].FromUsers) != 0 || sp[0].Terms != "words" || sp[0].IsHashtag || len(sp[0].InChannels) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp) } @@ -213,11 +213,11 @@ func TestParseSearchParams(t *testing.T) { t.Fatalf("Incorrect output from parse search params: %v", sp[0]) } - if sp := ParseSearchParams("##hashtag +#plus+"); len(sp) != 1 || sp[0].Terms != "#hashtag #plus" || sp[0].IsHashtag != true || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { + if sp := ParseSearchParams("##hashtag +#plus+"); len(sp) != 1 || sp[0].Terms != "#hashtag #plus" || !sp[0].IsHashtag || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp[0]) } - if sp := ParseSearchParams("wildcar*"); len(sp) != 1 || sp[0].Terms != "wildcar*" || sp[0].IsHashtag != false || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { + if sp := ParseSearchParams("wildcar*"); len(sp) != 1 || sp[0].Terms != "wildcar*" || sp[0].IsHashtag || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 { t.Fatalf("Incorrect output from parse search params: %v", sp[0]) } } diff --git a/model/status_test.go b/model/status_test.go index 7730ff0ed..4b15fb32e 100644 --- a/model/status_test.go +++ b/model/status_test.go @@ -61,8 +61,7 @@ func TestStatusListFromJson(t *testing.T) { } toDec := strings.NewReader(jsonStream) - var statusesFromJson []*Status - statusesFromJson = StatusListFromJson(toDec) + statusesFromJson := StatusListFromJson(toDec) if statusesFromJson[0].UserId != dat[0]["user_id"] { t.Fatal("UserId should be equal") diff --git a/model/utils.go b/model/utils.go index 01b24157a..e84d44f72 100644 --- a/model/utils.go +++ b/model/utils.go @@ -273,11 +273,7 @@ func GetServerIpAddress() string { } func IsLower(s string) bool { - if strings.ToLower(s) == s { - return true - } - - return false + return strings.ToLower(s) == s } func IsValidEmail(email string) bool { -- cgit v1.2.3-1-g7c22