components/iptypes.go
package components import ( str "strings" "github.com/knakk/rdf") // --------------------------------------------------------------------------------// TripleAggregate// -------------------------------------------------------------------------------- exported type TripleAggregate should have comment or be unexportedtype TripleAggregate struct { Subject rdf.Subject SubjectStr string Triples []rdf.Triple} exported function NewTripleAggregate should have comment or be unexportedfunc NewTripleAggregate(subj rdf.Subject, triples []rdf.Triple) *TripleAggregate { return &TripleAggregate{ Subject: subj, SubjectStr: subj.String(), Triples: triples, }} // --------------------------------------------------------------------------------// WikiPage// -------------------------------------------------------------------------------- exported type WikiPage should have comment or be unexportedtype WikiPage struct { Title string Type int Facts []*Fact Categories []*Category SpecificCategory *Category} Function `NewWikiPage` has 5 arguments (exceeds 4 allowed). Consider refactoring.
exported function NewWikiPage should have comment or be unexportedfunc NewWikiPage(title string, facts []*Fact, categories []*Category, specificCategory *Category, pageType int) *WikiPage { return &WikiPage{ Title: title, Facts: facts, Categories: categories, SpecificCategory: specificCategory, Type: pageType, }} exported method WikiPage.AddFact should have comment or be unexportedfunc (p *WikiPage) AddFact(fact *Fact) { p.Facts = append(p.Facts, fact)} exported method WikiPage.AddFactUnique should have comment or be unexportedfunc (p *WikiPage) AddFactUnique(fact *Fact) { factExists := false for _, existingFact := range p.Facts { if fact.Property == existingFact.Property && fact.Value == existingFact.Value { factExists = true break } } if !factExists { p.AddFact(fact) }} exported method WikiPage.AddCategory should have comment or be unexportedfunc (p *WikiPage) AddCategory(category *Category) { p.Categories = append(p.Categories, category)} exported method WikiPage.AddCategoryUnique should have comment or be unexportedfunc (p *WikiPage) AddCategoryUnique(category *Category) { catExists := false for _, existingCat := range p.Categories { if category.Name == existingCat.Name { catExists = true break } } if !catExists { p.AddCategory(category) }} // ------------------------------------------------------------// Helper type: Fact// ------------------------------------------------------------ exported type Fact should have comment or be unexportedtype Fact struct { Property string Value string} exported function NewFact should have comment or be unexportedfunc NewFact(property string, value string) *Fact { return &Fact{ Property: property, Value: value, }} func (f *Fact) asWikiFact() string { return "[[" + f.Property + "::" + f.escapeWikiChars(f.Value) + "]]\n"} Identical blocks of code found in 2 locations. Consider refactoring.func (f *Fact) escapeWikiChars(inStr string) string { outStr := str.Replace(inStr, "[", "(", -1) outStr = str.Replace(outStr, "]", ")", -1) outStr = str.Replace(outStr, "|", ",", -1) outStr = str.Replace(outStr, "=", "-", -1) outStr = str.Replace(outStr, "<", "<", -1) outStr = str.Replace(outStr, ">", ">", -1) return outStr} // ------------------------------------------------------------// Helper type: Category// ------------------------------------------------------------ exported type Category should have comment or be unexportedtype Category struct { Name string} exported function NewCategory should have comment or be unexportedfunc NewCategory(name string) *Category { return &Category{ Name: name, }} func (c *Category) asWikiString() string { return "[[Category:" + c.Name + "]]\n"}