diff options
author | Max Magorsch <arzano@gentoo.org> | 2020-03-21 13:18:48 +0100 |
---|---|---|
committer | Max Magorsch <arzano@gentoo.org> | 2020-03-21 13:18:48 +0100 |
commit | 8e12081ad77663937063721fa7cd9193b7c8e483 (patch) | |
tree | 8f9f34b0e1c1322174daf080e5d66bd6b8fc654a | |
parent | Correctly delete packages and versions when they are removed (diff) | |
download | soko-8e12081ad77663937063721fa7cd9193b7c8e483.tar.gz soko-8e12081ad77663937063721fa7cd9193b7c8e483.tar.bz2 soko-8e12081ad77663937063721fa7cd9193b7c8e483.zip |
Format the project using gofmt
Signed-off-by: Max Magorsch <arzano@gentoo.org>
46 files changed, 419 insertions, 438 deletions
diff --git a/pkg/app/handler/about/feedback.go b/pkg/app/handler/about/feedback.go index 2fb3e1e..24889d5 100644 --- a/pkg/app/handler/about/feedback.go +++ b/pkg/app/handler/about/feedback.go @@ -4,5 +4,5 @@ import "net/http" // Feedback shows the feedback about page func Feedback(w http.ResponseWriter, r *http.Request) { - renderAboutTemplate(w,r,"feedback") + renderAboutTemplate(w, r, "feedback") } diff --git a/pkg/app/handler/about/feeds.go b/pkg/app/handler/about/feeds.go index 5d6a538..3268d76 100644 --- a/pkg/app/handler/about/feeds.go +++ b/pkg/app/handler/about/feeds.go @@ -4,5 +4,5 @@ import "net/http" // Feeds shows the feeds about page func Feeds(w http.ResponseWriter, r *http.Request) { - renderAboutTemplate(w,r,"feeds") + renderAboutTemplate(w, r, "feeds") } diff --git a/pkg/app/handler/about/help.go b/pkg/app/handler/about/help.go index d78682c..d697146 100644 --- a/pkg/app/handler/about/help.go +++ b/pkg/app/handler/about/help.go @@ -4,5 +4,5 @@ import "net/http" // Help shows the help about page func Help(w http.ResponseWriter, r *http.Request) { - renderAboutTemplate(w,r,"help") + renderAboutTemplate(w, r, "help") } diff --git a/pkg/app/handler/about/index.go b/pkg/app/handler/about/index.go index e856f51..d2b1bdf 100644 --- a/pkg/app/handler/about/index.go +++ b/pkg/app/handler/about/index.go @@ -6,5 +6,5 @@ import ( // Index shows the landing page of the about pages func Index(w http.ResponseWriter, r *http.Request) { - renderAboutTemplate(w,r,"index") + renderAboutTemplate(w, r, "index") } diff --git a/pkg/app/handler/about/queries.go b/pkg/app/handler/about/queries.go index 80c327c..432fae9 100644 --- a/pkg/app/handler/about/queries.go +++ b/pkg/app/handler/about/queries.go @@ -4,5 +4,5 @@ import "net/http" // Queries shows the advanced search queries aboout page func Queries(w http.ResponseWriter, r *http.Request) { - renderAboutTemplate(w,r,"queries") + renderAboutTemplate(w, r, "queries") } diff --git a/pkg/app/handler/about/utils.go b/pkg/app/handler/about/utils.go index 6a1c897..cff240d 100644 --- a/pkg/app/handler/about/utils.go +++ b/pkg/app/handler/about/utils.go @@ -10,24 +10,24 @@ import ( ) // renderAboutTemplate renders a specific about template -func renderAboutTemplate(w http.ResponseWriter, r *http.Request, page string){ - templates := template.Must( - template.Must( - template.New(page). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/about/" + page + ".tmpl")) +func renderAboutTemplate(w http.ResponseWriter, r *http.Request, page string) { + templates := template.Must( + template.Must( + template.New(page). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/about/" + page + ".tmpl")) - templates.ExecuteTemplate(w, page + ".tmpl", getPageData()) + templates.ExecuteTemplate(w, page+".tmpl", getPageData()) } // getPageData returns the data used // in all about templates -func getPageData() interface{}{ +func getPageData() interface{} { return struct { - Page string - Application models.Application + Page string + Application models.Application }{ - Page: "about", - Application: utils.GetApplicationData(), + Page: "about", + Application: utils.GetApplicationData(), } } diff --git a/pkg/app/handler/arches/index.go b/pkg/app/handler/arches/index.go index e20bf29..97039fd 100644 --- a/pkg/app/handler/arches/index.go +++ b/pkg/app/handler/arches/index.go @@ -7,11 +7,11 @@ import ( // Index renders a template to show a the landing page containing links to all arches feeds func Index(w http.ResponseWriter, r *http.Request) { - templates := template.Must( - template.Must( - template.New("index"). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/arches/index.tmpl")) + templates := template.Must( + template.Must( + template.New("index"). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/arches/index.tmpl")) templates.ExecuteTemplate(w, "index.tmpl", getPageData()) } diff --git a/pkg/app/handler/arches/show.go b/pkg/app/handler/arches/show.go index 0238d71..b7ff7e7 100644 --- a/pkg/app/handler/arches/show.go +++ b/pkg/app/handler/arches/show.go @@ -9,13 +9,13 @@ import ( // Show renders a template to show a list of recently changed version by arch func Show(w http.ResponseWriter, r *http.Request) { urlParts := strings.Split(r.URL.Path[len("/arches/"):], "/") - if(len(urlParts) == 2){ - if(urlParts[1] == "stable"){ + if len(urlParts) == 2 { + if urlParts[1] == "stable" { stabilizedVersions := getStabilizedVersionsForArch(urlParts[0], 50) - renderPackageTemplates("changedVersions",packages.GetFuncMap(), createFeedData( urlParts[0], "Newly Stable", "stable", stabilizedVersions),w) - } else if(urlParts[1] == "keyworded"){ + renderPackageTemplates("changedVersions", packages.GetFuncMap(), createFeedData(urlParts[0], "Newly Stable", "stable", stabilizedVersions), w) + } else if urlParts[1] == "keyworded" { keywordedVersions := getKeywordedVersionsForArch(urlParts[0], 50) - renderPackageTemplates("changedVersions",packages.GetFuncMap(), createFeedData( urlParts[0], "Keyworded", "keyworded", keywordedVersions),w) + renderPackageTemplates("changedVersions", packages.GetFuncMap(), createFeedData(urlParts[0], "Keyworded", "keyworded", keywordedVersions), w) } } } diff --git a/pkg/app/handler/arches/utils.go b/pkg/app/handler/arches/utils.go index 792e3b1..5da97b0 100644 --- a/pkg/app/handler/arches/utils.go +++ b/pkg/app/handler/arches/utils.go @@ -12,13 +12,13 @@ import ( // getPageData creates the data used in all // templates used in the arches section -func getPageData() interface{}{ +func getPageData() interface{} { return struct { - Page string - Application models.Application + Page string + Application models.Application }{ - Page: "arches", - Application: utils.GetApplicationData(), + Page: "arches", + Application: utils.GetApplicationData(), } } @@ -31,15 +31,15 @@ func getStabilizedVersionsForArch(arch string, n int) []*models.Version { Relation("Version"). Relation("Commit"). Order("commit.preceding_commits DESC"). - Where("stabilized::jsonb @> ?", "\"" + arch + "\""). + Where("stabilized::jsonb @> ?", "\""+arch+"\""). Limit(n). Select() if err != nil { panic(err) } - for _, update := range updates{ - if(update.Version != nil){ + for _, update := range updates { + if update.Version != nil { update.Version.Commits = []*models.Commit{update.Commit} stabilizedVersions = append(stabilizedVersions, update.Version) } @@ -57,15 +57,15 @@ func getKeywordedVersionsForArch(arch string, n int) []*models.Version { Relation("Version"). Relation("Commit"). Order("commit.preceding_commits DESC"). - Where("added::jsonb @> ?", "\"" + arch + "\""). + Where("added::jsonb @> ?", "\""+arch+"\""). Limit(n). Select() if err != nil { panic(err) } - for _, update := range updates{ - if(update.Version != nil){ + for _, update := range updates { + if update.Version != nil { update.Version.Commits = []*models.Commit{update.Commit} stabilizedVersions = append(stabilizedVersions, update.Version) } @@ -75,35 +75,35 @@ func getKeywordedVersionsForArch(arch string, n int) []*models.Version { } // RenderPackageTemplates renders the arches templates using the given data -func renderPackageTemplates(page string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter){ +func renderPackageTemplates(page string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter) { templates := template.Must( - template.Must( - template.Must( - template.New(page). - Funcs(funcMap). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/packages/changedVersionRow.tmpl")). - ParseGlob("web/templates/arches/changedVersions.tmpl")) + template.Must( + template.Must( + template.New(page). + Funcs(funcMap). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/packages/changedVersionRow.tmpl")). + ParseGlob("web/templates/arches/changedVersions.tmpl")) templates.ExecuteTemplate(w, page+".tmpl", data) } // CreateFeedData creates the data used in changedVersions template -func createFeedData(arch string, name string, feedtype string, versions []*models.Version) interface{}{ +func createFeedData(arch string, name string, feedtype string, versions []*models.Version) interface{} { return struct { - Page string - Arch string - Name string - FeedName string - Versions []*models.Version - Application models.Application + Page string + Arch string + Name string + FeedName string + Versions []*models.Version + Application models.Application }{ - Page: "arches", - Arch: arch, - Name: name, - FeedName: feedtype, - Versions: versions, - Application: utils.GetApplicationData(), + Page: "arches", + Arch: arch, + Name: name, + FeedName: feedtype, + Versions: versions, + Application: utils.GetApplicationData(), } } diff --git a/pkg/app/handler/categories/index.go b/pkg/app/handler/categories/index.go index 1e09454..5093613 100644 --- a/pkg/app/handler/categories/index.go +++ b/pkg/app/handler/categories/index.go @@ -14,7 +14,7 @@ func Index(w http.ResponseWriter, r *http.Request) { var categories []*models.Category err := database.DBCon.Model(&categories).Order("name ASC").Select() if err != nil { - http.NotFound(w,r) + http.NotFound(w, r) return } diff --git a/pkg/app/handler/categories/show.go b/pkg/app/handler/categories/show.go index 1b9ee56..3b85e2b 100644 --- a/pkg/app/handler/categories/show.go +++ b/pkg/app/handler/categories/show.go @@ -13,12 +13,12 @@ func Show(w http.ResponseWriter, r *http.Request) { category := new(models.Category) err := database.DBCon.Model(category). - Where("name = ?", getCategoryName(r)). - Relation("Packages"). - Relation("Packages.Versions"). - Select() + Where("name = ?", getCategoryName(r)). + Relation("Packages"). + Relation("Packages.Versions"). + Select() if err != nil { - http.NotFound(w,r) + http.NotFound(w, r) return } diff --git a/pkg/app/handler/categories/utils.go b/pkg/app/handler/categories/utils.go index acd7e75..4d87e0d 100644 --- a/pkg/app/handler/categories/utils.go +++ b/pkg/app/handler/categories/utils.go @@ -17,39 +17,39 @@ func getCategoryName(r *http.Request) string { // createCategoriesData creates the data used in // the template to display all categories -func createCategoriesData(categories []*models.Category) interface{}{ +func createCategoriesData(categories []*models.Category) interface{} { return struct { - Page string + Page string Categories []*models.Category - Application models.Application + Application models.Application }{ - Page: "packages", - Categories: categories, + Page: "packages", + Categories: categories, Application: utils.GetApplicationData(), } } // createCategoriesData creates the data used in // the template to display a specific category -func createCategoryData(category models.Category) interface{}{ +func createCategoryData(category models.Category) interface{} { return struct { - Page string + Page string Category models.Category - Application models.Application + Application models.Application }{ - Page: "packages", - Category: category, + Page: "packages", + Category: category, Application: utils.GetApplicationData(), } } // renderIndexTemplate renders all templates used for the categories section -func renderCategoryTemplate(page string, data interface{}, w http.ResponseWriter){ - templates := template.Must( - template.Must( - template.New(page). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/categories/*.tmpl")) +func renderCategoryTemplate(page string, data interface{}, w http.ResponseWriter) { + templates := template.Must( + template.Must( + template.New(page). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/categories/*.tmpl")) - templates.ExecuteTemplate(w, page + ".tmpl", data) + templates.ExecuteTemplate(w, page+".tmpl", data) } diff --git a/pkg/app/handler/index/utils.go b/pkg/app/handler/index/utils.go index 1ca1b6c..7611b0e 100644 --- a/pkg/app/handler/index/utils.go +++ b/pkg/app/handler/index/utils.go @@ -45,26 +45,26 @@ func getUpdatedVersions(n int) []*models.Version { if err != nil { panic(err) } - for _, commit := range updates{ - for _, changedVersion := range commit.ChangedVersions{ + for _, commit := range updates { + for _, changedVersion := range commit.ChangedVersions { changedVersion.Commits = changedVersion.Commits[:1] } updatedVersions = append(updatedVersions, commit.ChangedVersions...) } - if(len(updatedVersions) > n){ + if len(updatedVersions) > n { updatedVersions = updatedVersions[:10] } return updatedVersions } // createPageData creates the data used in the template of the landing page -func createPageData(packagecount int, addedPackages []models.Package, updatedVersions []*models.Version) interface{}{ +func createPageData(packagecount int, addedPackages []models.Package, updatedVersions []*models.Version) interface{} { return struct { - Page string - PackageCount string - AddedPackages []models.Package - UpdatedPackages []*models.Version - Application models.Application + Page string + PackageCount string + AddedPackages []models.Package + UpdatedPackages []*models.Version + Application models.Application }{ Page: "home", Application: utils.GetApplicationData(), @@ -75,25 +75,24 @@ func createPageData(packagecount int, addedPackages []models.Package, updatedVer } // renderIndexTemplate renders all templates used for the landing page -func renderIndexTemplate(w http.ResponseWriter, pageData interface{}){ - templates := template.Must( - template.Must( - template.Must( - template.New("Show"). - Funcs(getFuncMap()). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/packages/changedVersionRow.tmpl")). - ParseGlob("web/templates/index/*.tmpl")) - +func renderIndexTemplate(w http.ResponseWriter, pageData interface{}) { + templates := template.Must( + template.Must( + template.Must( + template.New("Show"). + Funcs(getFuncMap()). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/packages/changedVersionRow.tmpl")). + ParseGlob("web/templates/index/*.tmpl")) templates.ExecuteTemplate(w, "show.tmpl", pageData) } // GetFuncMap returns the FuncMap used in templates -func getFuncMap() template.FuncMap{ +func getFuncMap() template.FuncMap { return template.FuncMap{ - "contains": strings.Contains, - "mkSlice": mkSlice, + "contains": strings.Contains, + "mkSlice": mkSlice, "formatRestricts": packages.FormatRestricts, } } @@ -106,9 +105,9 @@ func formatPackageCount(packageCount int) string { return packages[:3] + "," + packages[3:] } else if len(packages) == 5 { return packages[:2] + "," + packages[2:] - }else if len(packages) == 4 { + } else if len(packages) == 4 { return packages[:1] + "," + packages[1:] - }else{ + } else { return packages } } diff --git a/pkg/app/handler/packages/added.go b/pkg/app/handler/packages/added.go index 9204a05..fabea4b 100644 --- a/pkg/app/handler/packages/added.go +++ b/pkg/app/handler/packages/added.go @@ -8,5 +8,5 @@ import "net/http" // a list of 50 recently added versions func Added(w http.ResponseWriter, r *http.Request) { addedVersions := getAddedVersions(50) - RenderPackageTemplates("changedVersions","changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Added", addedVersions),w) + RenderPackageTemplates("changedVersions", "changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Added", addedVersions), w) } diff --git a/pkg/app/handler/packages/keyworded.go b/pkg/app/handler/packages/keyworded.go index 6975eb5..caa3d21 100644 --- a/pkg/app/handler/packages/keyworded.go +++ b/pkg/app/handler/packages/keyworded.go @@ -8,5 +8,5 @@ import "net/http" // a list of 50 recently keyworded versions func Keyworded(w http.ResponseWriter, r *http.Request) { keywordedVersions := GetKeywordedVersions(50) - RenderPackageTemplates("changedVersions","changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Keyworded", keywordedVersions),w) + RenderPackageTemplates("changedVersions", "changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Keyworded", keywordedVersions), w) } diff --git a/pkg/app/handler/packages/show.go b/pkg/app/handler/packages/show.go index 50da33e..058ecd6 100644 --- a/pkg/app/handler/packages/show.go +++ b/pkg/app/handler/packages/show.go @@ -15,7 +15,7 @@ import ( func Show(w http.ResponseWriter, r *http.Request) { if strings.HasSuffix(r.URL.Path, "/changelog.html") { - changelog(w,r) + changelog(w, r) return } @@ -28,17 +28,17 @@ func Show(w http.ResponseWriter, r *http.Request) { Select() if err != nil { - http.NotFound(w,r) + http.NotFound(w, r) return } localUseflags, globalUseflags, useExpands := getPackageUseflags(gpackage) renderPackageTemplate("show", - "*", - GetFuncMap(), - createPackageData(gpackage, localUseflags, globalUseflags, useExpands), - w) + "*", + GetFuncMap(), + createPackageData(gpackage, localUseflags, globalUseflags, useExpands), + w) } // changelog renders a template to show the changelog of a given package diff --git a/pkg/app/handler/packages/stabilized.go b/pkg/app/handler/packages/stabilized.go index b23f630..d6a6324 100644 --- a/pkg/app/handler/packages/stabilized.go +++ b/pkg/app/handler/packages/stabilized.go @@ -8,5 +8,5 @@ import "net/http" // a list of 50 recently stabilized versions func Stabilized(w http.ResponseWriter, r *http.Request) { stabilizedVersions := GetStabilizedVersions(50) - RenderPackageTemplates("changedVersions","changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Stabilized", stabilizedVersions),w) + RenderPackageTemplates("changedVersions", "changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Stabilized", stabilizedVersions), w) } diff --git a/pkg/app/handler/packages/suggest.go b/pkg/app/handler/packages/suggest.go index 5f09f3f..4552c07 100644 --- a/pkg/app/handler/packages/suggest.go +++ b/pkg/app/handler/packages/suggest.go @@ -24,20 +24,19 @@ func Suggest(w http.ResponseWriter, r *http.Request) { panic(err) } - - type Result struct{ - Name string `json:"name"` - Category string `json:"category"` + type Result struct { + Name string `json:"name"` + Category string `json:"category"` description string `json:"description"` } - type Results struct{ - Results []*Result `json:"results"` + type Results struct { + Results []*Result `json:"results"` } var results []*Result - for _, gpackage := range packages{ + for _, gpackage := range packages { results = append(results, &Result{ Name: gpackage.Name, Category: gpackage.Category, @@ -46,7 +45,7 @@ func Suggest(w http.ResponseWriter, r *http.Request) { } result := Results{ - Results: results, + Results: results, } b, err := json.Marshal(result) diff --git a/pkg/app/handler/packages/updated.go b/pkg/app/handler/packages/updated.go index 28674c0..0c5678f 100644 --- a/pkg/app/handler/packages/updated.go +++ b/pkg/app/handler/packages/updated.go @@ -8,5 +8,5 @@ import "net/http" // a list of 50 recently updated versions func Updated(w http.ResponseWriter, r *http.Request) { updatedVersions := GetUpdatedVersions(50) - RenderPackageTemplates("changedVersions","changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Updated", updatedVersions),w) + RenderPackageTemplates("changedVersions", "changedVersions", "changedVersionRow", GetFuncMap(), CreateFeedData("Updated", updatedVersions), w) } diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go index 71888f5..4b3129c 100644 --- a/pkg/app/handler/packages/utils.go +++ b/pkg/app/handler/packages/utils.go @@ -36,7 +36,7 @@ func getAddedPackages(n int) []*models.Package { func getAddedVersions(n int) []*models.Version { addedPackages := getAddedPackages(n) var addedVersions []*models.Version - for _, addedPackage := range addedPackages{ + for _, addedPackage := range addedPackages { addedVersions = append(addedVersions, addedPackage.Versions...) } return addedVersions @@ -58,13 +58,13 @@ func GetUpdatedVersions(n int) []*models.Version { if err != nil { panic(err) } - for _, commit := range updates{ - for _, changedVersion := range commit.ChangedVersions{ + for _, commit := range updates { + for _, changedVersion := range commit.ChangedVersions { changedVersion.Commits = changedVersion.Commits[:1] } updatedVersions = append(updatedVersions, commit.ChangedVersions...) } - if(len(updatedVersions) > n){ + if len(updatedVersions) > n { updatedVersions = updatedVersions[:10] } return updatedVersions @@ -85,8 +85,8 @@ func GetStabilizedVersions(n int) []*models.Version { if err != nil { panic(err) } - for _, update := range updates{ - if(update.Version != nil){ + for _, update := range updates { + if update.Version != nil { update.Version.Commits = []*models.Commit{update.Commit} stabilizedVersions = append(stabilizedVersions, update.Version) } @@ -109,8 +109,8 @@ func GetKeywordedVersions(n int) []*models.Version { if err != nil { panic(err) } - for _, update := range updates{ - if(update.Version != nil){ + for _, update := range updates { + if update.Version != nil { update.Version.Commits = []*models.Commit{update.Commit} stabilizedVersions = append(stabilizedVersions, update.Version) } @@ -120,27 +120,27 @@ func GetKeywordedVersions(n int) []*models.Version { // RenderPackageTemplates renders the given templates using the given data // One pattern can be used to specify templates -func renderPackageTemplate(page string, templatepattern string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter){ +func renderPackageTemplate(page string, templatepattern string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter) { templates := template.Must( - template.Must( - template.New(page). - Funcs(funcMap). - ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/packages/" + templatepattern + ".tmpl")) + template.Must( + template.New(page). + Funcs(funcMap). + ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/packages/" + templatepattern + ".tmpl")) templates.ExecuteTemplate(w, page+".tmpl", data) } // RenderPackageTemplates renders the given templates using the given data // Two patterns can be used to specify templates -func RenderPackageTemplates(page string, templatepattern1 string, templatepattern2 string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter){ +func RenderPackageTemplates(page string, templatepattern1 string, templatepattern2 string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter) { templates := template.Must( template.Must( template.Must( template.New(page). Funcs(funcMap). ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/packages/" + templatepattern1 + ".tmpl")). - ParseGlob("web/templates/packages/" + templatepattern2 + ".tmpl")) + ParseGlob("web/templates/packages/" + templatepattern1 + ".tmpl")). + ParseGlob("web/templates/packages/" + templatepattern2 + ".tmpl")) templates.ExecuteTemplate(w, page+".tmpl", data) } @@ -151,47 +151,47 @@ func getAtom(r *http.Request) string { } // getSearchData returns the data used in search templates -func getSearchData(packages []models.Package, search string) interface{}{ - return struct{ - Page string - Search string - Packages []models.Package - Application models.Application +func getSearchData(packages []models.Package, search string) interface{} { + return struct { + Page string + Search string + Packages []models.Package + Application models.Application }{ - Page: "packages", - Search: search, - Packages: packages, - Application: utils.GetApplicationData(), + Page: "packages", + Search: search, + Packages: packages, + Application: utils.GetApplicationData(), } } // getChangelogData returns the data used in changelog templates -func getChangelogData(commits []*models.Commit, atom string) interface{}{ +func getChangelogData(commits []*models.Commit, atom string) interface{} { return struct { - Commits []*models.Commit - Atom string + Commits []*models.Commit + Atom string }{ - Commits: commits, - Atom: atom, + Commits: commits, + Atom: atom, } } // GetFuncMap returns the FuncMap used in templates -func GetFuncMap() template.FuncMap{ +func GetFuncMap() template.FuncMap { return template.FuncMap{ - "contains": strings.Contains, - "replaceall": strings.ReplaceAll, - "gravatar": gravatar, - "mkSlice": mkSlice, - "getReverse": getReverse, - "tolower": strings.ToLower, + "contains": strings.Contains, + "replaceall": strings.ReplaceAll, + "gravatar": gravatar, + "mkSlice": mkSlice, + "getReverse": getReverse, + "tolower": strings.ToLower, "formatRestricts": FormatRestricts, } } // gravatar creates a link to the gravatar // based on the email -func gravatar(email string) string{ +func gravatar(email string) string { hasher := md5.Sum([]byte(email)) hash := hex.EncodeToString(hasher[:]) return "https://www.gravatar.com/avatar/" + hash + "?s=13&d=retro" @@ -204,7 +204,7 @@ func mkSlice(args ...interface{}) []interface{} { // getReverse returns the element of a slice in // reverse direction based on the index -func getReverse(index int, versions []*models.Version) *models.Version{ +func getReverse(index int, versions []*models.Version) *models.Version { return versions[len(versions)-1-index] } @@ -219,64 +219,63 @@ func getParameterValue(parameterName string, r *http.Request) string { // flags and use expands for a given package func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Useflag, []models.Useflag) { var localUseflags, globalUseflags, useExpands []models.Useflag - for _, useflag := range gpackage.Versions[len(gpackage.Versions)-1].Useflags{ + for _, useflag := range gpackage.Versions[len(gpackage.Versions)-1].Useflags { var tmp_useflags []models.Useflag err := database.DBCon.Model(&tmp_useflags). - Where("Name LIKE ?", "%" + strings.Replace(useflag, "+", "", 1)). + Where("Name LIKE ?", "%"+strings.Replace(useflag, "+", "", 1)). Select() if err != nil { panic(err) } - if(len(tmp_useflags) >= 1 && tmp_useflags[0].Scope == "global"){ + if len(tmp_useflags) >= 1 && tmp_useflags[0].Scope == "global" { globalUseflags = append(globalUseflags, tmp_useflags[0]) - }else if(len(tmp_useflags) >= 1 && tmp_useflags[0].Scope == "local") { + } else if len(tmp_useflags) >= 1 && tmp_useflags[0].Scope == "local" { localUseflags = append(localUseflags, tmp_useflags[0]) - }else if(len(tmp_useflags) >= 1){ + } else if len(tmp_useflags) >= 1 { useExpands = append(useExpands, tmp_useflags[0]) } } return localUseflags, globalUseflags, useExpands } - // createPackageData creates the data used in the show package template -func createPackageData(gpackage *models.Package, localUseflags []models.Useflag, globalUseflags []models.Useflag, useExpands []models.Useflag) interface{}{ +func createPackageData(gpackage *models.Package, localUseflags []models.Useflag, globalUseflags []models.Useflag, useExpands []models.Useflag) interface{} { return struct { - Page string - Package models.Package - Versions []*models.Version - Masks []models.Mask - LocalUseflags []models.Useflag - GlobalUseflags []models.Useflag - UseExpands []models.Useflag - Application models.Application + Page string + Package models.Package + Versions []*models.Version + Masks []models.Mask + LocalUseflags []models.Useflag + GlobalUseflags []models.Useflag + UseExpands []models.Useflag + Application models.Application }{ - Page: "packages", - Package: *gpackage, - Versions: gpackage.Versions, - LocalUseflags: localUseflags, - GlobalUseflags: globalUseflags, - UseExpands: useExpands, - Masks: nil, - Application: utils.GetApplicationData(), + Page: "packages", + Package: *gpackage, + Versions: gpackage.Versions, + LocalUseflags: localUseflags, + GlobalUseflags: globalUseflags, + UseExpands: useExpands, + Masks: nil, + Application: utils.GetApplicationData(), } } // CreateFeedData creates the data used in changedVersions template -func CreateFeedData(name string, versions []*models.Version) interface{}{ +func CreateFeedData(name string, versions []*models.Version) interface{} { return struct { - Page string - Name string - Versions []*models.Version - Application models.Application + Page string + Name string + Versions []*models.Version + Application models.Application }{ - Page: "packages", - Name: name, - Versions: versions, - Application: utils.GetApplicationData(), + Page: "packages", + Name: name, + Versions: versions, + Application: utils.GetApplicationData(), } } @@ -284,7 +283,7 @@ func CreateFeedData(name string, versions []*models.Version) interface{}{ // list of capitalized first letters of the package restricts func FormatRestricts(restricts []string) string { var result []string - for _, restrict := range restricts{ + for _, restrict := range restricts { if restrict != "(" && restrict != ")" && !strings.HasSuffix(restrict, "?") { result = append(result, strings.ToUpper(string(restrict[0]))) } diff --git a/pkg/app/handler/useflags/index.go b/pkg/app/handler/useflags/index.go index 0edba0c..c432e04 100644 --- a/pkg/app/handler/useflags/index.go +++ b/pkg/app/handler/useflags/index.go @@ -14,17 +14,17 @@ import ( func Index(w http.ResponseWriter, r *http.Request) { data := struct { - Page string + Page string Application models.Application }{ - Page: "useflags", + Page: "useflags", Application: utils2.GetApplicationData(), } - templates := template.Must( - template.Must( - template.New("Show").ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/useflags/index.tmpl")) + templates := template.Must( + template.Must( + template.New("Show").ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/useflags/index.tmpl")) templates.ExecuteTemplate(w, "index.tmpl", data) } diff --git a/pkg/app/handler/useflags/popular.go b/pkg/app/handler/useflags/popular.go index a768f27..130949b 100644 --- a/pkg/app/handler/useflags/popular.go +++ b/pkg/app/handler/useflags/popular.go @@ -21,24 +21,24 @@ func Popular(w http.ResponseWriter, r *http.Request) { panic(err) } - dict:= make(map[string]int) - for _ , version := range versions { - for _ , useflag := range version.Useflags { - if (useflag != "test" && useflag != "doc" && useflag != "debug" && len(strings.Split(useflag, "_")) < 2) { + dict := make(map[string]int) + for _, version := range versions { + for _, useflag := range version.Useflags { + if useflag != "test" && useflag != "doc" && useflag != "debug" && len(strings.Split(useflag, "_")) < 2 { dict[strings.ReplaceAll(useflag, "+", "")] = dict[strings.ReplaceAll(useflag, "+", "")] + 1 } } } type kv struct { - Key string `json:"name"` - Value int `json:"size"` + Key string `json:"name"` + Value int `json:"size"` Children types.Object `json:"children"` } type p struct { - Name string `json:"name"` - Children []kv `json:"children"` + Name string `json:"name"` + Children []kv `json:"children"` } var ss []kv @@ -50,7 +50,6 @@ func Popular(w http.ResponseWriter, r *http.Request) { return ss[i].Value > ss[j].Value }) - popular := p{ Name: "flags", Children: ss[0:66], @@ -58,7 +57,6 @@ func Popular(w http.ResponseWriter, r *http.Request) { b, err := json.Marshal(popular) - w.Header().Set("Content-Type", "application/json") w.Write(b) } diff --git a/pkg/app/handler/useflags/search.go b/pkg/app/handler/useflags/search.go index 028464e..779e1b4 100644 --- a/pkg/app/handler/useflags/search.go +++ b/pkg/app/handler/useflags/search.go @@ -24,24 +24,22 @@ func Search(w http.ResponseWriter, r *http.Request) { panic(err) } - data := struct { - Page string - Search string - Useflags []models.Useflag - Application models.Application + Page string + Search string + Useflags []models.Useflag + Application models.Application }{ - Page: "useflags", - Search: param, - Useflags: useflags, + Page: "useflags", + Search: param, + Useflags: useflags, Application: utils2.GetApplicationData(), - } - templates := template.Must( - template.Must( - template.New("Show").ParseGlob("web/templates/layout/*.tmpl")). - ParseGlob("web/templates/useflags/search.tmpl")) + templates := template.Must( + template.Must( + template.New("Show").ParseGlob("web/templates/layout/*.tmpl")). + ParseGlob("web/templates/useflags/search.tmpl")) templates.ExecuteTemplate(w, "search.tmpl", data) } diff --git a/pkg/app/handler/useflags/show.go b/pkg/app/handler/useflags/show.go index acf1c06..0149169 100644 --- a/pkg/app/handler/useflags/show.go +++ b/pkg/app/handler/useflags/show.go @@ -20,38 +20,37 @@ func Show(w http.ResponseWriter, r *http.Request) { var useflags []models.Useflag err := database.DBCon.Model(&useflags).Where("name = ? ", useflagName).Select() if err != nil || len(useflags) < 1 { - http.NotFound(w,r) + http.NotFound(w, r) return } useflag := useflags[0] var localuseflags []models.Useflag - for _, use := range useflags{ - if(use.Scope == "global"){ + for _, use := range useflags { + if use.Scope == "global" { useflag = use - }else if(use.Scope == "local"){ + } else if use.Scope == "local" { localuseflags = append(localuseflags, use) - }else if(use.Scope == "use_expand"){ + } else if use.Scope == "use_expand" { ShowUseExpand(w, r, use) return } } var versions []models.Version - err = database.DBCon.Model(&versions).Column("atom").Where("useflags::jsonb @> ?", "\"" + useflagName + "\"").Select() + err = database.DBCon.Model(&versions).Column("atom").Where("useflags::jsonb @> ?", "\""+useflagName+"\"").Select() if err != nil { panic(err) } var packages []string - for _, version := range versions{ + for _, version := range versions { packages = append(packages, version.Atom) } packages = utils.Deduplicate(packages) - data := struct { Page string Useflag models.Useflag @@ -59,14 +58,14 @@ func Show(w http.ResponseWriter, r *http.Request) { Packages []string Application models.Application }{ - Page: "useflags", - Useflag: useflag, + Page: "useflags", + Useflag: useflag, LocalUseflags: localuseflags, - Packages: packages, - Application: utils2.GetApplicationData(), + Packages: packages, + Application: utils2.GetApplicationData(), } - templates := template.Must( + templates := template.Must( template.Must( template.New("Show").ParseGlob("web/templates/layout/*.tmpl")). ParseGlob("web/templates/useflags/show.tmpl")) @@ -88,33 +87,33 @@ func ShowUseExpand(w http.ResponseWriter, r *http.Request, useExpand models.Usef } var versions []models.Version - err = database.DBCon.Model(&versions).Column("atom").Where("useflags::jsonb @> ?", "\"" + useExpand.Name + "\"").Select() + err = database.DBCon.Model(&versions).Column("atom").Where("useflags::jsonb @> ?", "\""+useExpand.Name+"\"").Select() if err != nil { panic(err) } var packages []string - for _, version := range versions{ + for _, version := range versions { packages = append(packages, version.Atom) } packages = utils.Deduplicate(packages) data := struct { - Page string - Useflag models.Useflag + Page string + Useflag models.Useflag OtherUseExpands []models.Useflag - Packages []string - Application models.Application + Packages []string + Application models.Application }{ - Page: "useflags", - Useflag: useExpand, + Page: "useflags", + Useflag: useExpand, OtherUseExpands: otheruseexpands, - Packages: packages, - Application: utils2.GetApplicationData(), + Packages: packages, + Application: utils2.GetApplicationData(), } - templates := template.Must( + templates := template.Must( template.Must( template.New("Show").Funcs(funcMap).ParseGlob("web/templates/layout/*.tmpl")). ParseGlob("web/templates/useflags/showexpand.tmpl")) diff --git a/pkg/app/handler/useflags/suggest.go b/pkg/app/handler/useflags/suggest.go index bb55f3e..2fc73e8 100644 --- a/pkg/app/handler/useflags/suggest.go +++ b/pkg/app/handler/useflags/suggest.go @@ -27,28 +27,27 @@ func Suggest(w http.ResponseWriter, r *http.Request) { } type Suggest struct { - Id string `json:"id"` - Name string `json:"name"` + Id string `json:"id"` + Name string `json:"name"` Description string `json:"description"` } type Suggestions struct { - Results []Suggest `json:"results"` + Results []Suggest `json:"results"` } - var suggests []Suggest - for _, useflag := range useflags{ + for _, useflag := range useflags { suggests = append(suggests, Suggest{ - Id: useflag.Id, - Name: useflag.Name, - Description: useflag.Description, + Id: useflag.Id, + Name: useflag.Name, + Description: useflag.Description, }) } suggestions := Suggestions{ - Results: suggests, + Results: suggests, } jsondata, err := json.Marshal(suggestions) diff --git a/pkg/app/serve.go b/pkg/app/serve.go index d6bd175..6e5fec9 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -3,13 +3,13 @@ package app import ( + "log" + "net/http" "soko/pkg/app/handler/about" "soko/pkg/app/handler/arches" "soko/pkg/app/handler/categories" "soko/pkg/app/handler/index" "soko/pkg/app/handler/packages" - "log" - "net/http" "soko/pkg/app/handler/useflags" "soko/pkg/config" "soko/pkg/database" @@ -51,6 +51,6 @@ func Serve() { fs := http.StripPrefix("/assets/", http.FileServer(http.Dir("/go/src/soko/assets"))) http.Handle("/assets/", fs) - log.Fatal(http.ListenAndServe(":" + config.Port(), nil)) + log.Fatal(http.ListenAndServe(":"+config.Port(), nil)) } diff --git a/pkg/app/utils/applicationdata.go b/pkg/app/utils/applicationdata.go index 0882074..7cafcb2 100644 --- a/pkg/app/utils/applicationdata.go +++ b/pkg/app/utils/applicationdata.go @@ -10,7 +10,7 @@ import ( // GetApplicationData is used to retrieve the // application data from the database -func GetApplicationData() models.Application{ +func GetApplicationData() models.Application { // Select user by primary key. applicationData := &models.Application{Id: "latest"} err := database.DBCon.Select(applicationData) diff --git a/pkg/config/config.go b/pkg/config/config.go index fbc4b39..dae0f54 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -42,11 +42,10 @@ func Port() string { return getEnv("SOKO_PORT", "5000") } - -func getEnv(key string, fallback string) string{ - if os.Getenv("") != ""{ +func getEnv(key string, fallback string) string { + if os.Getenv("") != "" { return os.Getenv(key) - }else{ + } else { return fallback } } diff --git a/pkg/database/connection.go b/pkg/database/connection.go index e978007..ffedf4b 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -21,14 +21,14 @@ var ( // in case they don't alreay exist func CreateSchema() error { for _, model := range []interface{}{(*models.Package)(nil), - (*models.Category)(nil), - (*models.Version)(nil), - (*models.Commit)(nil), - (*models.KeywordChange)(nil), - (*models.CommitToPackage)(nil), - (*models.CommitToVersion)(nil), - (*models.Useflag)(nil), - (*models.Application)(nil)} { + (*models.Category)(nil), + (*models.Version)(nil), + (*models.Commit)(nil), + (*models.KeywordChange)(nil), + (*models.CommitToPackage)(nil), + (*models.CommitToVersion)(nil), + (*models.Useflag)(nil), + (*models.Application)(nil)} { err := DBCon.CreateTable(model, &orm.CreateTableOptions{ IfNotExists: true, @@ -41,7 +41,7 @@ func CreateSchema() error { return nil } -type dbLogger struct { } +type dbLogger struct{} func (d dbLogger) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) { return c, nil @@ -60,10 +60,10 @@ func Connect() { User: config.PostgresUser(), Password: config.PostgresPass(), Database: config.PostgresDb(), - Addr: config.PostgresHost() + ":" + config.PostgresPort(), + Addr: config.PostgresHost() + ":" + config.PostgresPort(), }) - if(config.Debug() == "true"){ + if config.Debug() == "true" { DBCon.AddQueryHook(dbLogger{}) } diff --git a/pkg/models/application.go b/pkg/models/application.go index b24b5cb..513fa8d 100644 --- a/pkg/models/application.go +++ b/pkg/models/application.go @@ -5,8 +5,8 @@ package models import "time" type Application struct { - Id string `pg:",pk"` - LastUpdate time.Time - LastCommit string - Version string + Id string `pg:",pk"` + LastUpdate time.Time + LastCommit string + Version string } diff --git a/pkg/models/category.go b/pkg/models/category.go index cb38830..a1a073c 100644 --- a/pkg/models/category.go +++ b/pkg/models/category.go @@ -3,7 +3,7 @@ package models type Category struct { - Name string `pg:",pk"` - Description string - Packages []*Package `pg:",fk:category"` + Name string `pg:",pk"` + Description string + Packages []*Package `pg:",fk:category"` } diff --git a/pkg/models/commit.go b/pkg/models/commit.go index 6ee6bf0..d6fa710 100644 --- a/pkg/models/commit.go +++ b/pkg/models/commit.go @@ -5,53 +5,53 @@ package models import "time" type Commit struct { - Id string `pg:",pk"` - PrecedingCommits int - AuthorName string - AuthorEmail string - AuthorDate time.Time - CommitterName string - CommitterEmail string - CommitterDate time.Time - Message string - ChangedFiles *ChangedFiles - ChangedPackages []*Package `pg:"many2many:commit_to_packages,joinFK:package_atom"` - ChangedVersions []*Version `pg:"many2many:commit_to_versions,joinFK:version_id"` - KeywordChanges []*KeywordChange `pg:",fk:commit_id"` + Id string `pg:",pk"` + PrecedingCommits int + AuthorName string + AuthorEmail string + AuthorDate time.Time + CommitterName string + CommitterEmail string + CommitterDate time.Time + Message string + ChangedFiles *ChangedFiles + ChangedPackages []*Package `pg:"many2many:commit_to_packages,joinFK:package_atom"` + ChangedVersions []*Version `pg:"many2many:commit_to_versions,joinFK:version_id"` + KeywordChanges []*KeywordChange `pg:",fk:commit_id"` } type ChangedFiles struct { - Added []*ChangedFile - Modified []*ChangedFile - Deleted []*ChangedFile + Added []*ChangedFile + Modified []*ChangedFile + Deleted []*ChangedFile } type ChangedFile struct { - Path string - ChangeType string + Path string + ChangeType string } type KeywordChange struct { - Id string `pg:",pk"` - CommitId string - Commit *Commit `pg:",fk:commit_id"` - VersionId string - Version *Version `pg:",fk:version_id"` - PackageId string - Package *Package `pg:",fk:package_id"` - Added []string - Stabilized []string - All []string + Id string `pg:",pk"` + CommitId string + Commit *Commit `pg:",fk:commit_id"` + VersionId string + Version *Version `pg:",fk:version_id"` + PackageId string + Package *Package `pg:",fk:package_id"` + Added []string + Stabilized []string + All []string } type CommitToPackage struct { - Id string `pg:",pk"` - CommitId string - PackageAtom string + Id string `pg:",pk"` + CommitId string + PackageAtom string } type CommitToVersion struct { - Id string `pg:",pk"` - CommitId string - VersionId string + Id string `pg:",pk"` + CommitId string + VersionId string } diff --git a/pkg/models/masks.go b/pkg/models/masks.go index 81b4038..d7adca0 100644 --- a/pkg/models/masks.go +++ b/pkg/models/masks.go @@ -3,5 +3,5 @@ package models type Mask struct { - Description string + Description string } diff --git a/pkg/models/package.go b/pkg/models/package.go index 436a975..06492ee 100644 --- a/pkg/models/package.go +++ b/pkg/models/package.go @@ -3,19 +3,19 @@ package models type Package struct { - Atom string `pg:",pk"` - Category string - Name string - Versions []*Version `pg:",fk:atom"` - Longdescription string - Maintainers []*Maintainer - Commits []*Commit `pg:"many2many:commit_to_packages,joinFK:commit_id"` - PrecedingCommits int + Atom string `pg:",pk"` + Category string + Name string + Versions []*Version `pg:",fk:atom"` + Longdescription string + Maintainers []*Maintainer + Commits []*Commit `pg:"many2many:commit_to_packages,joinFK:commit_id"` + PrecedingCommits int } type Maintainer struct { - Name string - Email string - Type string - Restrict string + Name string + Email string + Type string + Restrict string } diff --git a/pkg/models/useflag.go b/pkg/models/useflag.go index 0179028..98cffa7 100644 --- a/pkg/models/useflag.go +++ b/pkg/models/useflag.go @@ -3,10 +3,10 @@ package models type Useflag struct { - Id string `pg:",pk"` - Name string - Scope string - Description string - UseExpand string - Package string + Id string `pg:",pk"` + Name string + Scope string + Description string + UseExpand string + Package string } diff --git a/pkg/models/version.go b/pkg/models/version.go index 8747f1c..c9a5130 100644 --- a/pkg/models/version.go +++ b/pkg/models/version.go @@ -3,20 +3,20 @@ package models type Version struct { - Id string `pg:",pk"` - Category string - Package string - Atom string - Version string - Slot string - Subslot string - EAPI string - Keywords string - Useflags []string - Restricts []string - Properties []string - Homepage []string - License string - Description string - Commits []*Commit `pg:"many2many:commit_to_versions,joinFK:commit_id"` + Id string `pg:",pk"` + Category string + Package string + Atom string + Version string + Slot string + Subslot string + EAPI string + Keywords string + Useflags []string + Restricts []string + Properties []string + Homepage []string + License string + Description string + Commits []*Commit `pg:"many2many:commit_to_versions,joinFK:commit_id"` } diff --git a/pkg/portage/repository/category.go b/pkg/portage/repository/category.go index a088da5..b9aa476 100644 --- a/pkg/portage/repository/category.go +++ b/pkg/portage/repository/category.go @@ -42,17 +42,17 @@ func UpdateCategory(path string) { } // updateDeletedCategory deletes a category from the database -func updateDeletedCategory(changedFile string){ +func updateDeletedCategory(changedFile string) { splitted := strings.Split(changedFile, "/") id := splitted[0] - category := &models.Category{ Name: id } + category := &models.Category{Name: id} database.DBCon.Model(category).Delete() } // updateModifiedCategory adds a category to the database or // updates it. To do so, it parses the metadata from metadata.xml -func updateModifiedCategory(changedFile string){ +func updateModifiedCategory(changedFile string) { splitted := strings.Split(changedFile, "/") id := splitted[0] @@ -60,7 +60,7 @@ func updateModifiedCategory(changedFile string){ description := "" for _, longdescription := range catmetadata.Longdescriptions { - if (longdescription.Lang == "en") { + if longdescription.Lang == "en" { description = strings.TrimSpace(longdescription.Content) } } @@ -79,7 +79,7 @@ func updateModifiedCategory(changedFile string){ // GetCatMetadata reads and parses the category // metadata from the metadata.xml file -func GetCatMetadata(path string) Catmetadata{ +func GetCatMetadata(path string) Catmetadata { xmlFile, err := os.Open(path) if err != nil { fmt.Println(err) @@ -91,16 +91,15 @@ func GetCatMetadata(path string) Catmetadata{ return catmetadata } - // Descriptions of the category metadata.xml format type Catmetadata struct { - XMLName xml.Name `xml:"catmetadata"` + XMLName xml.Name `xml:"catmetadata"` Longdescriptions []Longdescription `xml:"longdescription"` } type Longdescription struct { - XMLName xml.Name `xml:"longdescription"` + XMLName xml.Name `xml:"longdescription"` Lang string `xml:"lang,attr"` - Content string `xml:",chardata"` + Content string `xml:",chardata"` } diff --git a/pkg/portage/repository/commit.go b/pkg/portage/repository/commit.go index 40f3171..a4db12e 100644 --- a/pkg/portage/repository/commit.go +++ b/pkg/portage/repository/commit.go @@ -31,9 +31,8 @@ func UpdateCommits() string { return latestCommit } - // processCommit parses a single commit log output and updates it into the database -func processCommit(PrecedingCommits int, PrecedingCommitsOffset int, rawCommit string) string{ +func processCommit(PrecedingCommits int, PrecedingCommitsOffset int, rawCommit string) string { commitLines := strings.Split(rawCommit, "\n") @@ -110,7 +109,7 @@ func processChangedFiles(PrecedingCommits int, PrecedingCommitsOffset int, commi } else if strings.HasPrefix(commitLine, "A") { addedFiles = addChangedFile(addedFiles, path, "A") - updateFirstCommitOfPackage(path, commitLine, PrecedingCommitsOffset + PrecedingCommits + 1) + updateFirstCommitOfPackage(path, commitLine, PrecedingCommitsOffset+PrecedingCommits+1) createAddedKeywords(id, path, commitLine) } @@ -137,13 +136,12 @@ func logProgess(counter int) { } } - -func linkCommitToPackage(commitLine string, path string, id string){ +func linkCommitToPackage(commitLine string, path string, id string) { var commitToPackage *models.CommitToPackage if (len(strings.Split(commitLine, "/")) >= 3) && (strings.HasPrefix(commitLine, "M") || - strings.HasPrefix(commitLine, "D") || - strings.HasPrefix(commitLine, "A")) { + strings.HasPrefix(commitLine, "D") || + strings.HasPrefix(commitLine, "A")) { pathParts := strings.Split(strings.ReplaceAll(path, ".ebuild", ""), "/") @@ -162,8 +160,7 @@ func linkCommitToPackage(commitLine string, path string, id string){ } } - -func linkCommitToVersion(commitLine string, path string, id string){ +func linkCommitToVersion(commitLine string, path string, id string) { var commitToVersion *models.CommitToVersion if (strings.HasPrefix(commitLine, "M") || strings.HasPrefix(commitLine, "D") || @@ -188,8 +185,7 @@ func linkCommitToVersion(commitLine string, path string, id string){ } } - -func createKeywordChange(id string, path string, commitLine string){ +func createKeywordChange(id string, path string, commitLine string) { if !strings.HasSuffix(path, ".ebuild") || !(len(strings.Split(commitLine, "/")) >= 3) { return @@ -253,8 +249,7 @@ func createKeywordChange(id string, path string, commitLine string){ } } - -func createAddedKeywords(id string, path string, commitLine string){ +func createAddedKeywords(id string, path string, commitLine string) { var change *models.KeywordChange if strings.HasSuffix(strings.TrimSpace(strings.Split(commitLine, "\t")[1]), ".ebuild") && (len(strings.Split(commitLine, "/")) >= 3) { @@ -294,8 +289,7 @@ func createAddedKeywords(id string, path string, commitLine string){ } } - -func updateFirstCommitOfPackage(path string, commitLine string, precedingCommits int){ +func updateFirstCommitOfPackage(path string, commitLine string, precedingCommits int) { // Added Package if strings.HasSuffix(path, "metadata.xml") && len(strings.Split(path, "/")) == 3 { @@ -312,8 +306,7 @@ func updateFirstCommitOfPackage(path string, commitLine string, precedingCommits } } - -func addChangedFile(changedFiles []*models.ChangedFile, path string, status string) []*models.ChangedFile{ +func addChangedFile(changedFiles []*models.ChangedFile, path string, status string) []*models.ChangedFile { return append(changedFiles, &models.ChangedFile{ Path: path, ChangeType: status, diff --git a/pkg/portage/repository/package.go b/pkg/portage/repository/package.go index 695167e..855e67e 100644 --- a/pkg/portage/repository/package.go +++ b/pkg/portage/repository/package.go @@ -43,13 +43,13 @@ func UpdatePackage(path string) { } // updateDeletedPackage deletes a package from the database -func updateDeletedPackage(changedFile string){ +func updateDeletedPackage(changedFile string) { splitted := strings.Split(changedFile, "/") category := splitted[0] packagename := splitted[1] atom := category + "/" + packagename - gpackage := &models.Package{ Atom: atom } + gpackage := &models.Package{Atom: atom} _, err := database.DBCon.Model(gpackage).WherePK().Delete() if err != nil { @@ -60,7 +60,7 @@ func updateDeletedPackage(changedFile string){ // updateModifiedPackage adds a package to the database or // updates it. To do so, it parses the metadata from metadata.xml -func updateModifiedPackage(changedFile string){ +func updateModifiedPackage(changedFile string) { splitted := strings.Split(changedFile, "/") category := splitted[0] packagename := splitted[1] @@ -114,19 +114,18 @@ func GetPkgMetadata(path string) Pkgmetadata { return pkgmetadata } - // Descriptions of the package metadata.xml format type Pkgmetadata struct { - XMLName xml.Name `xml:"pkgmetadata"` - MaintainerList []Maintainer `xml:"maintainer"` - Longdescription string `xml:"longdescription"` + XMLName xml.Name `xml:"pkgmetadata"` + MaintainerList []Maintainer `xml:"maintainer"` + Longdescription string `xml:"longdescription"` } type Maintainer struct { - XMLName xml.Name `xml:"maintainer"` - Type string `xml:"type,attr"` - Restrict string `xml:"restrict,attr"` + XMLName xml.Name `xml:"maintainer"` + Type string `xml:"type,attr"` + Restrict string `xml:"restrict,attr"` Email string `xml:"email"` - Name string `xml:"name"` + Name string `xml:"name"` } diff --git a/pkg/portage/repository/use.go b/pkg/portage/repository/use.go index a430ea7..48278c4 100644 --- a/pkg/portage/repository/use.go +++ b/pkg/portage/repository/use.go @@ -13,7 +13,7 @@ import ( // UpdateUse reads all USE flags descriptions from the given file in // case the given file contains USE flags descriptions and imports // each USE flag into the database -func UpdateUse(path string){ +func UpdateUse(path string) { splittedLine := strings.Split(path, "\t") @@ -34,9 +34,9 @@ func UpdateUse(path string){ scope := getScope(changedFile) var err error - if scope == "local" || scope == "global"{ + if scope == "local" || scope == "global" { err = createUseflag(rawFlag, scope) - } else if scope == "use_expand"{ + } else if scope == "use_expand" { file := strings.Split(changedFile, "/")[2] err = createUseExpand(rawFlag, file) } @@ -56,16 +56,16 @@ func createUseflag(rawFlag string, scope string) error { splitted := strings.Split(line[0], ":") gpackage := "" - if scope == "local"{ + if scope == "local" { gpackage = splitted[0] } useflag := &models.Useflag{ - Id: line[0] + "-" + scope, - Package: gpackage, - Name: splitted[len(splitted)-1], - Scope: scope, - Description: strings.Join(line[1:], ""), + Id: line[0] + "-" + scope, + Package: gpackage, + Name: splitted[len(splitted)-1], + Scope: scope, + Description: strings.Join(line[1:], ""), } _, err := database.DBCon.Model(useflag).OnConflict("(id) DO UPDATE").Insert() @@ -76,16 +76,16 @@ func createUseflag(rawFlag string, scope string) error { // createUseExpand parses the description from the file, // creates a USE expand flag and imports it into the database func createUseExpand(rawFlag string, file string) error { - name := strings.ReplaceAll(file, ".desc","") + name := strings.ReplaceAll(file, ".desc", "") line := strings.Split(rawFlag, " - ") id := name + "_" + line[0] useExpand := &models.Useflag{ - Id: id, - Name: name + "_" + line[0], - Scope: "use_expand", - Description: strings.Join(line[1:], ""), - UseExpand: name, + Id: id, + Name: name + "_" + line[0], + Scope: "use_expand", + Description: strings.Join(line[1:], ""), + UseExpand: name, } _, err := database.DBCon.Model(useExpand).OnConflict("(id) DO UPDATE").Insert() diff --git a/pkg/portage/repository/version.go b/pkg/portage/repository/version.go index f27fb06..db465d7 100644 --- a/pkg/portage/repository/version.go +++ b/pkg/portage/repository/version.go @@ -40,7 +40,7 @@ func UpdateVersion(path string) { } // updateDeletedVersion deletes a package version from the database -func updateDeletedVersion(changedFile string){ +func updateDeletedVersion(changedFile string) { splitted := strings.Split(strings.ReplaceAll(changedFile, ".ebuild", ""), "/") category := splitted[0] packagename := splitted[1] @@ -60,7 +60,7 @@ func updateDeletedVersion(changedFile string){ // updateModifiedVersion adds a package version to the database or // updates it. To do so, it parses the metadata from the md5-cache -func updateModifiedVersion(changedFile string){ +func updateModifiedVersion(changedFile string) { splitted := strings.Split(strings.ReplaceAll(changedFile, ".ebuild", ""), "/") category := splitted[0] packagename := splitted[1] diff --git a/pkg/portage/update.go b/pkg/portage/update.go index 36b509f..5cd7f27 100644 --- a/pkg/portage/update.go +++ b/pkg/portage/update.go @@ -48,7 +48,7 @@ func Update() { // retrieving the last commit in the database (if present) and parsing all // following commits. In case no last commit is present a full import // starting with the first commit in the tree is done. -func updateMetadata(){ +func updateMetadata() { log.Print("Start updating changed metadata") @@ -68,7 +68,7 @@ func updateMetadata(){ // - packages // - versions // changed data is determined by parsing all commits since the last update. -func updatePackageData(){ +func updatePackageData() { log.Print("Start updating changed package data") @@ -86,17 +86,17 @@ func updatePackageData(){ // determined by retrieving the last commit in the database (if present) // and parsing all following commits. In case no last commit is present // a full import starting with the first commit in the tree is done. -func updateHistory(){ +func updateHistory() { log.Print("Start updating the history") latestCommit := repository.UpdateCommits() application := &models.Application{ - Id: "latest", - LastUpdate: time.Now(), - Version: config.Version(), - LastCommit: latestCommit, + Id: "latest", + LastUpdate: time.Now(), + Version: config.Version(), + LastCommit: latestCommit, } _, err := database.DBCon.Model(application). diff --git a/pkg/portage/utils/exec.go b/pkg/portage/utils/exec.go index 45c0ecc..421710c 100644 --- a/pkg/portage/utils/exec.go +++ b/pkg/portage/utils/exec.go @@ -14,5 +14,5 @@ func Exec(dir string, command string, arg ...string) ([]string, error) { cmd.Dir = dir out, err := cmd.CombinedOutput() - return strings.Split(strings.TrimSpace(string(out)),"\n"), err + return strings.Split(strings.TrimSpace(string(out)), "\n"), err } diff --git a/pkg/portage/utils/git.go b/pkg/portage/utils/git.go index 42e7ca0..5212b44 100644 --- a/pkg/portage/utils/git.go +++ b/pkg/portage/utils/git.go @@ -17,9 +17,9 @@ import ( func ChangedFiles(startCommit string, endCommit string) []string { cmd := exec.Command("git", "--no-pager", - "diff", - "--name-status", - startCommit + ".." + endCommit) + "diff", + "--name-status", + startCommit+".."+endCommit) cmd.Dir = config.PortDir() out, err := cmd.CombinedOutput() @@ -27,7 +27,7 @@ func ChangedFiles(startCommit string, endCommit string) []string { log.Fatalf("cmd.Run() failed with %s\n", err) } - return strings.Split(string(out),"\n") + return strings.Split(string(out), "\n") } // GetCommits returns the log message of all commits after @@ -41,14 +41,14 @@ func ChangedFiles(startCommit string, endCommit string) []string { func GetCommits(startCommit string, endCommit string) []string { cmd := exec.Command("git", "--no-pager", - "log", - "--name-status", - "--no-renames", - "--no-merges", - "--date=format:'%Y-%m-%dT%H:%M:%S%z'", - "--format=fuller", - "--reverse", - startCommit + ".." + endCommit) + "log", + "--name-status", + "--no-renames", + "--no-merges", + "--date=format:'%Y-%m-%dT%H:%M:%S%z'", + "--format=fuller", + "--reverse", + startCommit+".."+endCommit) cmd.Dir = config.PortDir() out, err := cmd.CombinedOutput() @@ -56,7 +56,7 @@ func GetCommits(startCommit string, endCommit string) []string { log.Fatalf("cmd.Run() failed with %s\n", err) } - return strings.Split(string(out),"\n\ncommit") + return strings.Split(string(out), "\n\ncommit") } // GetLatestCommit retrieves the latest commit in diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 711cfef..d9d9641 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -4,8 +4,8 @@ import "sort" // Deduplicate accepts a slice of strings and returns // a slice which only contains unique items. -func Deduplicate(items []string) []string{ - if(items != nil && len(items) > 1){ +func Deduplicate(items []string) []string { + if items != nil && len(items) > 1 { sort.Strings(items) j := 0 for i := 1; i < len(items); i++ { @@ -20,7 +20,7 @@ func Deduplicate(items []string) []string{ } result := items[:j+1] return result - }else{ + } else { return items } } @@ -8,13 +8,13 @@ import ( "time" ) -func printHelp(){ +func printHelp() { fmt.Println("Please specific one of the following options:") fmt.Println(" soko update -- update the database") fmt.Println(" soko serve -- serve the application") } -func isCommand(command string) bool{ +func isCommand(command string) bool { return len(os.Args) > 1 && os.Args[1] == command } @@ -22,11 +22,11 @@ func main() { time.Sleep(5 * time.Second) - if(isCommand("serve")) { + if isCommand("serve") { app.Serve() - }else if(isCommand("update")){ + } else if isCommand("update") { portage.Update() - }else{ + } else { printHelp() } |