Skip to content
Snippets Groups Projects
Commit b71d13f8 authored by Linus's avatar Linus :thinking:
Browse files

fix some antipatterns

parent bb6cfbd8
No related branches found
No related tags found
No related merge requests found
// Package apbtime handles time functions
package apbtime
import (
......
......@@ -115,7 +115,7 @@ func saveConfirmations(file string) error {
return err
}
err = ioutil.WriteFile(file, []byte(buf.String()), 0644)
err = ioutil.WriteFile(file, buf.Bytes(), 0644)
if err != nil {
return err
}
......
......@@ -56,7 +56,7 @@ func doDel(w http.ResponseWriter, r *http.Request) error {
}
i := 0
for _, listing := range value {
if strings.ToLower(listing.GetEmail()) != strings.ToLower(email) {
if !strings.EqualFold(listing.GetEmail(), email) {
value[i] = listing
i++
}
......
......@@ -11,10 +11,6 @@ import (
"git.rwth-aachen.de/h/apb/subjects"
)
/*
Search for listings
*/
func tutSwapSearch(w http.ResponseWriter, r *http.Request) error {
return listingSearch(&swapListings, w, r)
}
......@@ -74,7 +70,7 @@ func listingSearch(l structs.ListingMap, w http.ResponseWriter, r *http.Request)
resultFolderName = "swap"
foundTemplate = "templates/tutswap_found.html"
default:
return errors.New("Invalid type of ListingMap")
return errors.New("invalid type of ListingMap")
}
var resultTemplate string
......
// Package mail handles sending emails.
package mail
import (
......@@ -37,7 +38,7 @@ func GetEmail(id string) (string, error) {
if id, ok := mailLookup[id]; ok {
return id, nil
}
return "", errors.New("This id does not exist")
return "", errors.New("this id does not exist")
}
// GetURL gets the email URL (for convenience's sake, it is only configured once, here)
......
......@@ -59,9 +59,7 @@ func main() {
clearTicker := time.NewTicker(1 * time.Hour)
go func() {
for {
select {
case <-clearTicker.C:
for range clearTicker.C {
err := clearOldListings(&partnerListings)
if err != nil {
log.Fatal(err)
......@@ -72,7 +70,6 @@ func main() {
log.Fatal(err)
}
}
}
}()
err = clearOldListings(&partnerListings)
if err != nil {
......
// Package structs manages the data structures
package structs
import (
......
......@@ -25,7 +25,7 @@ func (p *PartnerMap) GetEntries(key string) []Listing {
func (p *PartnerMap) Push(subject string, l Listing) error {
partnerListing, ok := l.(*PartnerListing)
if !ok {
return errors.New("Invalid type")
return errors.New("invalid type")
}
partnerMutex.Lock()
defer partnerMutex.Unlock()
......@@ -45,7 +45,7 @@ func (p *PartnerMap) Clear(key string) {
func (p *PartnerMap) Remove(subject string, toRemove Listing) error {
partnerListing, ok := toRemove.(*PartnerListing)
if !ok {
return errors.New("Invalid type")
return errors.New("invalid type")
}
partnerMutex.Lock()
defer partnerMutex.Unlock()
......@@ -55,7 +55,7 @@ func (p *PartnerMap) Remove(subject string, toRemove Listing) error {
return nil
}
}
return errors.New("Element to remove does not exist")
return errors.New("element to remove does not exist")
}
func NewPartnerMap() ListingMap {
......
......@@ -25,7 +25,7 @@ func (p *SwapMap) GetEntries(key string) []Listing {
func (p *SwapMap) Push(subject string, l Listing) error {
tutSwapListing, ok := l.(*TutSwapListing)
if !ok {
return errors.New("Invalid type")
return errors.New("invalid type")
}
swapMutex.Lock()
defer swapMutex.Unlock()
......@@ -34,7 +34,7 @@ func (p *SwapMap) Push(subject string, l Listing) error {
}
func (p *SwapMap) GetMap() map[string][]Listing {
toReturn := map[string][]Listing{}
for key, _ := range *p {
for key := range *p {
toReturn[key] = p.GetEntries(key)
}
return toReturn
......@@ -45,7 +45,7 @@ func (p *SwapMap) Clear(key string) {
func (p *SwapMap) Remove(subject string, toRemove Listing) error {
tutSwapListing, ok := toRemove.(*TutSwapListing)
if !ok {
return errors.New("Invalid type")
return errors.New("invalid type")
}
swapMutex.Lock()
defer swapMutex.Unlock()
......@@ -55,7 +55,7 @@ func (p *SwapMap) Remove(subject string, toRemove Listing) error {
return nil
}
}
return errors.New("Element to remove does not exist")
return errors.New("element to remove does not exist")
}
func NewSwapMap() ListingMap {
......@@ -63,6 +63,6 @@ func NewSwapMap() ListingMap {
}
type ToSend struct {
EmailId string
EmailID string
Listing Listing
}
// Package subjects manages the subject list
package subjects
import (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment