From c459b31aa816a9a4627121c2c1cc3737ecbb5afa Mon Sep 17 00:00:00 2001 From: Umputun Date: Sat, 11 Aug 2018 11:29:31 -0500 Subject: [PATCH] fix typos in struct names --- backend/app/main.go | 22 +++++++++++----------- backend/app/rest/api/rest.go | 14 +++++++------- backend/app/rest/api/rest_private.go | 4 ++-- backend/app/rest/api/rest_public.go | 2 +- backend/app/rest/api/rest_test.go | 16 ++++++++-------- backend/app/store/fomrater.go | 24 ++++++++++++------------ backend/app/store/formater_test.go | 20 ++++++++++---------- 7 files changed, 51 insertions(+), 51 deletions(-) diff --git a/backend/app/main.go b/backend/app/main.go index acc7a748..c15ba681 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -219,19 +219,19 @@ func New(opts Opts) (*Application, error) { authProviders := makeAuthProviders(jwtService, avatarProxy, dataService, opts) imgProxy := &proxy.Image{Enabled: opts.ImageProxy, RoutePath: "/api/v1/img", RemarkURL: opts.RemarkURL} - commentFormater := store.NewCommentFormater(imgProxy) + commentFormatter := store.NewCommentFormatter(imgProxy) srv := &api.Rest{ - Version: revision, - DataService: dataService, - Exporter: exporter, - WebRoot: opts.WebRoot, - RemarkURL: opts.RemarkURL, - ImageProxy: imgProxy, - CommentFormater: commentFormater, - AvatarProxy: avatarProxy, - ReadOnlyAge: opts.ReadOnlyAge, - SharedSecret: opts.SharedSecret, + Version: revision, + DataService: dataService, + Exporter: exporter, + WebRoot: opts.WebRoot, + RemarkURL: opts.RemarkURL, + ImageProxy: imgProxy, + CommentFormatter: commentFormatter, + AvatarProxy: avatarProxy, + ReadOnlyAge: opts.ReadOnlyAge, + SharedSecret: opts.SharedSecret, Authenticator: auth.Authenticator{ JWTService: jwtService, AdminEmail: opts.AdminEmail, diff --git a/backend/app/rest/api/rest.go b/backend/app/rest/api/rest.go index 7746e936..0a4b71cf 100644 --- a/backend/app/rest/api/rest.go +++ b/backend/app/rest/api/rest.go @@ -34,13 +34,13 @@ import ( type Rest struct { Version string - DataService *service.DataStore - Authenticator auth.Authenticator - Exporter migrator.Exporter - Cache cache.LoadingCache - AvatarProxy *proxy.Avatar - ImageProxy *proxy.Image - CommentFormater *store.CommentFormater + DataService *service.DataStore + Authenticator auth.Authenticator + Exporter migrator.Exporter + Cache cache.LoadingCache + AvatarProxy *proxy.Avatar + ImageProxy *proxy.Image + CommentFormatter *store.CommentFormatter WebRoot string RemarkURL string diff --git a/backend/app/rest/api/rest_private.go b/backend/app/rest/api/rest_private.go index b8250593..6f1edd0a 100644 --- a/backend/app/rest/api/rest_private.go +++ b/backend/app/rest/api/rest_private.go @@ -43,7 +43,7 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) { rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "invalid comment") return } - comment = s.CommentFormater.Format(comment) + comment = s.CommentFormatter.Format(comment) // check if user blocked if s.adminService.checkBlocked(comment.Locator.SiteID, comment.User) { @@ -109,7 +109,7 @@ func (s *Rest) updateCommentCtrl(w http.ResponseWriter, r *http.Request) { } editReq := service.EditRequest{ - Text: s.CommentFormater.FormatText(edit.Text), + Text: s.CommentFormatter.FormatText(edit.Text), Orig: edit.Text, Summary: edit.Summary, } diff --git a/backend/app/rest/api/rest_public.go b/backend/app/rest/api/rest_public.go index 5315ebc0..6ee667bd 100644 --- a/backend/app/rest/api/rest_public.go +++ b/backend/app/rest/api/rest_public.go @@ -78,7 +78,7 @@ func (s *Rest) previewCommentCtrl(w http.ResponseWriter, r *http.Request) { return } - comment = s.CommentFormater.Format(comment) + comment = s.CommentFormatter.Format(comment) comment.Sanitize() render.HTML(w, r, comment.Text) } diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go index 218dfb05..43a2f76c 100644 --- a/backend/app/rest/api/rest_test.go +++ b/backend/app/rest/api/rest_test.go @@ -91,14 +91,14 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) { AdminEmail: "admin@remark-42.com", JWTService: auth.NewJWT(keys.NewStaticStore("123456"), false, time.Minute, time.Hour), }, - Exporter: &migrator.Remark{DataStore: dataStore}, - Cache: &cache.Nop{}, - WebRoot: "/tmp", - RemarkURL: "https://demo.remark42.com", - AvatarProxy: &proxy.Avatar{Store: avatar.NewLocalFS("/tmp", 300), RoutePath: "/api/v1/avatar"}, - ImageProxy: &proxy.Image{}, - ReadOnlyAge: 10, - CommentFormater: store.NewCommentFormater(&proxy.Image{}), + Exporter: &migrator.Remark{DataStore: dataStore}, + Cache: &cache.Nop{}, + WebRoot: "/tmp", + RemarkURL: "https://demo.remark42.com", + AvatarProxy: &proxy.Avatar{Store: avatar.NewLocalFS("/tmp", 300), RoutePath: "/api/v1/avatar"}, + ImageProxy: &proxy.Image{}, + ReadOnlyAge: 10, + CommentFormatter: store.NewCommentFormatter(&proxy.Image{}), } srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = -5, -10 diff --git a/backend/app/store/fomrater.go b/backend/app/store/fomrater.go index 2154d4f3..e51d7192 100644 --- a/backend/app/store/fomrater.go +++ b/backend/app/store/fomrater.go @@ -8,30 +8,30 @@ import ( blackfriday "gopkg.in/russross/blackfriday.v2" ) -// CommentFormater implements all generic formatings ops on comment -type CommentFormater struct { +// CommentFormatter implements all generic formatting ops on comment +type CommentFormatter struct { converters []CommentConverter } // CommentConverter defines interface to convert some parts of commentHTML -// Passed at creation time and does client-defined convertions, like image proxy link change +// Passed at creation time and does client-defined conversions, like image proxy link change type CommentConverter interface { Convert(text string) string } -// NewCommentFormater makes CommentFormater -func NewCommentFormater(converters ...CommentConverter) *CommentFormater { - return &CommentFormater{converters: converters} +// NewCommentFormatter makes CommentFormatter +func NewCommentFormatter(converters ...CommentConverter) *CommentFormatter { + return &CommentFormatter{converters: converters} } // Format comment fields -func (f *CommentFormater) Format(c Comment) Comment { +func (f *CommentFormatter) Format(c Comment) Comment { c.Text = f.FormatText(c.Text) return c } // FormatText formatting line -func (f *CommentFormater) FormatText(txt string) (res string) { +func (f *CommentFormatter) FormatText(txt string) (res string) { mdExt := blackfriday.NoIntraEmphasis | blackfriday.Tables | blackfriday.FencedCode | blackfriday.Strikethrough | blackfriday.SpaceHeadings | blackfriday.HardLineBreak | blackfriday.BackslashLineBreak | blackfriday.Autolink @@ -45,7 +45,7 @@ func (f *CommentFormater) FormatText(txt string) (res string) { } // Shortens all the automatic links in HTML: auto link has equal "href" and "text" attributes. -func (f *CommentFormater) shortenAutoLinks(commentHTML string, max int) (resHTML string) { +func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTML string) { doc, err := goquery.NewDocumentFromReader(strings.NewReader(commentHTML)) if err != nil { return commentHTML @@ -55,12 +55,12 @@ func (f *CommentFormater) shortenAutoLinks(commentHTML string, max int) (resHTML if href != s.Text() || len(href) < max+3 || max < 3 { return } - url, e := url.Parse(href) + commentURL, e := url.Parse(href) if e != nil { return } - url.Path, url.RawQuery, url.Fragment = "", "", "" - host := url.String() + commentURL.Path, commentURL.RawQuery, commentURL.Fragment = "", "", "" + host := commentURL.String() if host == "" { return } diff --git a/backend/app/store/formater_test.go b/backend/app/store/formater_test.go index cd33f24a..38465114 100644 --- a/backend/app/store/formater_test.go +++ b/backend/app/store/formater_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/assert" ) -type mockConvertor struct{} +type mockConverter struct{} -func (m mockConvertor) Convert(text string) string { return text + "!converted" } +func (m mockConverter) Convert(text string) string { return text + "!converted" } -func TestFormater_FormatText(t *testing.T) { +func TestFormatter_FormatText(t *testing.T) { tbl := []struct { in, out string }{ @@ -22,18 +22,18 @@ func TestFormater_FormatText(t *testing.T) { "http://127.0.0.1/some-long-link/12345/678901234567890", "

http://127.0.0.1/some-long-link/12345/6789012...

\n!converted", }, } - f := NewCommentFormater(mockConvertor{}) + f := NewCommentFormatter(mockConverter{}) for n, tt := range tbl { assert.Equal(t, tt.out, f.FormatText(tt.in), "check #%d", n) } } -func TestFormater_FormatTextNoConvertor(t *testing.T) { - f := NewCommentFormater() +func TestFormatter_FormatTextNoConvertor(t *testing.T) { + f := NewCommentFormatter() assert.Equal(t, "

12345

\n", f.FormatText("12345")) } -func TestFormater_FormatComment(t *testing.T) { +func TestFormatter_FormatComment(t *testing.T) { comment := Comment{ Text: `blah`, User: User{ID: "username"}, @@ -47,14 +47,14 @@ func TestFormater_FormatComment(t *testing.T) { Votes: map[string]bool{"uu": true}, } - f := NewCommentFormater(mockConvertor{}) + f := NewCommentFormatter(mockConverter{}) exp := comment exp.Text = "

blah

\n!converted" assert.Equal(t, exp, f.Format(comment)) } -func TestFormater_ShortenAutoLinks(t *testing.T) { - f := NewCommentFormater(nil) +func TestFormatter_ShortenAutoLinks(t *testing.T) { + f := NewCommentFormatter(nil) tbl := []struct { max int in, out string