From 12aa41d8c8d81806fe4f6fa22ac3b054689961b6 Mon Sep 17 00:00:00 2001 From: Joseph Spurrier Date: Sun, 24 Apr 2016 11:09:13 -0400 Subject: [PATCH] Updated variables names according to Lint --- controller/about.go | 2 +- controller/index.go | 4 +- controller/login.go | 11 ++- controller/register.go | 8 +- gowebapp.go | 16 ++-- model/bolt/user.go | 49 +++++----- model/mongo/user.go | 49 +++++----- model/sql/user.go | 51 +++++----- model/user.go | 95 ++++++++++--------- .../httprouterwrapper/httprouterwrapper.go | 6 +- route/route.go | 10 +- shared/database/database.go | 61 +++++++----- shared/passhash/passhash.go | 8 +- shared/recaptcha/recaptcha.go | 14 +-- shared/view/view.go | 20 ++-- 15 files changed, 219 insertions(+), 185 deletions(-) diff --git a/controller/about.go b/controller/about.go index 97d467c..40df6b0 100644 --- a/controller/about.go +++ b/controller/about.go @@ -6,7 +6,7 @@ import ( "github.com/josephspurrier/gowebapp/shared/view" ) -// Displays the About page +// AboutGET displays the About page func AboutGET(w http.ResponseWriter, r *http.Request) { // Display the view v := view.New(r) diff --git a/controller/index.go b/controller/index.go index 09011c1..34014bf 100644 --- a/controller/index.go +++ b/controller/index.go @@ -7,8 +7,8 @@ import ( "github.com/josephspurrier/gowebapp/shared/view" ) -// Displays the default home page -func Index(w http.ResponseWriter, r *http.Request) { +// IndexGET displays the home page +func IndexGET(w http.ResponseWriter, r *http.Request) { // Get session session := session.Instance(r) diff --git a/controller/login.go b/controller/login.go index cb0a739..752b6c1 100644 --- a/controller/login.go +++ b/controller/login.go @@ -29,6 +29,7 @@ func loginAttempt(sess *sessions.Session) { } } +// LoginGET displays the login page func LoginGET(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) @@ -42,6 +43,7 @@ func LoginGET(w http.ResponseWriter, r *http.Request) { v.Render(w) } +// LoginPOST handles the login form submission func LoginPOST(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) @@ -81,7 +83,7 @@ func LoginPOST(w http.ResponseWriter, r *http.Request) { sess.AddFlash(view.Flash{"There was an error. Please try again later.", view.FlashError}) sess.Save(r, w) } else if passhash.MatchString(result.Password, password) { - if result.Status_id != 1 { + if result.StatusID != 1 { // User inactive and display inactive message sess.AddFlash(view.Flash{"Account is inactive so login is disabled.", view.FlashNotice}) sess.Save(r, w) @@ -89,9 +91,9 @@ func LoginPOST(w http.ResponseWriter, r *http.Request) { // Login successfully session.Empty(sess) sess.AddFlash(view.Flash{"Login successful!", view.FlashSuccess}) - sess.Values["id"] = result.ID() + sess.Values["id"] = result.UserID() sess.Values["email"] = email - sess.Values["first_name"] = result.First_name + sess.Values["first_name"] = result.FirstName sess.Save(r, w) http.Redirect(w, r, "/", http.StatusFound) return @@ -106,7 +108,8 @@ func LoginPOST(w http.ResponseWriter, r *http.Request) { LoginGET(w, r) } -func Logout(w http.ResponseWriter, r *http.Request) { +// LogoutGET clears the session and logs the user out +func LogoutGET(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) diff --git a/controller/register.go b/controller/register.go index 482cf08..e96a683 100644 --- a/controller/register.go +++ b/controller/register.go @@ -13,6 +13,7 @@ import ( "github.com/josephspurrier/csrfbanana" ) +// RegisterGET displays the register page func RegisterGET(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) @@ -26,6 +27,7 @@ func RegisterGET(w http.ResponseWriter, r *http.Request) { v.Render(w) } +// RegisterPOST handles the registration form submission func RegisterPOST(w http.ResponseWriter, r *http.Request) { // Get session sess := session.Instance(r) @@ -54,8 +56,8 @@ func RegisterPOST(w http.ResponseWriter, r *http.Request) { } // Get form values - first_name := r.FormValue("first_name") - last_name := r.FormValue("last_name") + firstName := r.FormValue("first_name") + lastName := r.FormValue("last_name") email := r.FormValue("email") password, errp := passhash.HashString(r.FormValue("password")) @@ -72,7 +74,7 @@ func RegisterPOST(w http.ResponseWriter, r *http.Request) { _, err := model.UserByEmail(email) if err == model.ErrNoResult { // If success (no user exists with that email) - ex := model.UserCreate(first_name, last_name, email, password) + ex := model.UserCreate(firstName, lastName, email, password) // Will only error if there is a problem with the query if ex != nil { log.Println(ex) diff --git a/gowebapp.go b/gowebapp.go index 9a173c7..5caa5af 100644 --- a/gowebapp.go +++ b/gowebapp.go @@ -48,7 +48,7 @@ func main() { view.LoadPlugins( plugin.TagHelper(config.View), plugin.NoEscape(), - recaptcha.RecaptchaPlugin()) + recaptcha.Plugin()) // Start the listener server.Run(route.LoadHTTP(), route.LoadHTTPS(), config.Server) @@ -63,13 +63,13 @@ var config = &configuration{} // configuration contains the application settings type configuration struct { - Database database.DatabaseInfo `json:"Database"` - Email email.SMTPInfo `json:"Email"` - Recaptcha recaptcha.RecaptchaInfo `json:"Recaptcha"` - Server server.Server `json:"Server"` - Session session.Session `json:"Session"` - Template view.Template `json:"Template"` - View view.View `json:"View"` + Database database.Info `json:"Database"` + Email email.SMTPInfo `json:"Email"` + Recaptcha recaptcha.Info `json:"Recaptcha"` + Server server.Server `json:"Server"` + Session session.Session `json:"Session"` + Template view.Template `json:"Template"` + View view.View `json:"View"` } // ParseJSON unmarshals bytes to structs diff --git a/model/bolt/user.go b/model/bolt/user.go index 579c8da..3a4b854 100644 --- a/model/bolt/user.go +++ b/model/bolt/user.go @@ -15,25 +15,28 @@ import ( // User table contains the information for each user type User struct { - ObjectId bson.ObjectId `bson:"_id"` - First_name string `db:"first_name" bson:"first_name"` - Last_name string `db:"last_name" bson:"last_name"` - Email string `db:"email" bson:"email"` - Password string `db:"password" bson:"password"` - Status_id uint8 `db:"status_id" bson:"status_id"` - Created_at time.Time `db:"created_at" bson:"created_at"` - Updated_at time.Time `db:"updated_at" bson:"updated_at"` - Deleted uint8 `db:"deleted" bson:"deleted"` + ObjectID bson.ObjectId `bson:"_id"` + FirstName string `db:"first_name" bson:"first_name"` + LastName string `db:"last_name" bson:"last_name"` + Email string `db:"email" bson:"email"` + Password string `db:"password" bson:"password"` + StatusID uint8 `db:"status_id" bson:"status_id"` + CreatedAt time.Time `db:"created_at" bson:"created_at"` + UpdatedAt time.Time `db:"updated_at" bson:"updated_at"` + Deleted uint8 `db:"deleted" bson:"deleted"` } var ( - ErrCode = errors.New("Case statement in code is not correct.") - ErrNoResult = errors.New("Result not found.") + // ErrCode is a config or an internal error + ErrCode = errors.New("Case statement in code is not correct.") + // ErrNoResult is a not results error + ErrNoResult = errors.New("Result not found.") + // ErrUnavailable is a database not available error ErrUnavailable = errors.New("Database is unavailable.") ) -// Id returns the user id -func (u *User) ID() string { +// UserID returns the user id +func (u *User) UserID() string { return u.ObjectId.Hex() } @@ -57,21 +60,21 @@ func UserByEmail(email string) (User, error) { } // UserCreate creates user -func UserCreate(first_name, last_name, email, password string) error { +func UserCreate(firstName, lastName, email, password string) error { var err error now := time.Now() user := &User{ - ObjectId: bson.NewObjectId(), - First_name: first_name, - Last_name: last_name, - Email: email, - Password: password, - Status_id: 1, - Created_at: now, - Updated_at: now, - Deleted: 0, + ObjectID: bson.NewObjectId(), + FirstName: firstName, + LastName: lastName, + Email: email, + Password: password, + StatusID: 1, + CreatedAt: now, + UpdatedAt: now, + Deleted: 0, } err = database.Update("user", user.Email, &user) diff --git a/model/mongo/user.go b/model/mongo/user.go index 0afb56f..9bb5d95 100644 --- a/model/mongo/user.go +++ b/model/mongo/user.go @@ -16,25 +16,28 @@ import ( // User table contains the information for each user type User struct { - ObjectId bson.ObjectId `bson:"_id"` - First_name string `db:"first_name" bson:"first_name"` - Last_name string `db:"last_name" bson:"last_name"` - Email string `db:"email" bson:"email"` - Password string `db:"password" bson:"password"` - Status_id uint8 `db:"status_id" bson:"status_id"` - Created_at time.Time `db:"created_at" bson:"created_at"` - Updated_at time.Time `db:"updated_at" bson:"updated_at"` - Deleted uint8 `db:"deleted" bson:"deleted"` + ObjectID bson.ObjectId `bson:"_id"` + FirstName string `db:"first_name" bson:"first_name"` + LastName string `db:"last_name" bson:"last_name"` + Email string `db:"email" bson:"email"` + Password string `db:"password" bson:"password"` + StatusID uint8 `db:"status_id" bson:"status_id"` + CreatedAt time.Time `db:"created_at" bson:"created_at"` + UpdatedAt time.Time `db:"updated_at" bson:"updated_at"` + Deleted uint8 `db:"deleted" bson:"deleted"` } var ( - ErrCode = errors.New("Case statement in code is not correct.") - ErrNoResult = errors.New("Result not found.") + // ErrCode is a config or an internal error + ErrCode = errors.New("Case statement in code is not correct.") + // ErrNoResult is a not results error + ErrNoResult = errors.New("Result not found.") + // ErrUnavailable is a database not available error ErrUnavailable = errors.New("Database is unavailable.") ) -// Id returns the user id -func (u *User) ID() string { +// UserID returns the user id +func (u *User) UserID() string { return u.ObjectId.Hex() } @@ -66,7 +69,7 @@ func UserByEmail(email string) (User, error) { } // UserCreate creates user -func UserCreate(first_name, last_name, email, password string) error { +func UserCreate(firstName, lastName, email, password string) error { var err error now := time.Now() @@ -77,15 +80,15 @@ func UserCreate(first_name, last_name, email, password string) error { c := session.DB(database.ReadConfig().MongoDB.Database).C("user") user := &User{ - ObjectId: bson.NewObjectId(), - First_name: first_name, - Last_name: last_name, - Email: email, - Password: password, - Status_id: 1, - Created_at: now, - Updated_at: now, - Deleted: 0, + ObjectID: bson.NewObjectId(), + FirstName: firstName, + LastName: lastName, + Email: email, + Password: password, + StatusID: 1, + CreatedAt: now, + UpdatedAt: now, + Deleted: 0, } err = c.Insert(user) } else { diff --git a/model/sql/user.go b/model/sql/user.go index 366ae8b..e41d7d3 100644 --- a/model/sql/user.go +++ b/model/sql/user.go @@ -15,34 +15,37 @@ import ( // User table contains the information for each user type User struct { - Id uint32 `db:"id"` - First_name string `db:"first_name"` - Last_name string `db:"last_name"` - Email string `db:"email"` - Password string `db:"password"` - Status_id uint8 `db:"status_id"` - Created_at time.Time `db:"created_at"` - Updated_at time.Time `db:"updated_at"` - Deleted uint8 `db:"deleted"` + ID uint32 `db:"id"` + FirstName string `db:"first_name"` + LastName string `db:"last_name"` + Email string `db:"email"` + Password string `db:"password"` + StatusID uint8 `db:"status_id"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt time.Time `db:"updated_at"` + Deleted uint8 `db:"deleted"` } -// User_status table contains every possible user status (active/inactive) -type User_status struct { - Id uint8 `db:"id"` - Status string `db:"status"` - Created_at time.Time `db:"created_at"` - Updated_at time.Time `db:"updated_at"` - Deleted uint8 `db:"deleted"` +// UserStatus table contains every possible user status (active/inactive) +type UserStatus struct { + ID uint8 `db:"id"` + Status string `db:"status"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt time.Time `db:"updated_at"` + Deleted uint8 `db:"deleted"` } var ( - ErrCode = errors.New("Case statement in code is not correct.") - ErrNoResult = errors.New("Result not found.") + // ErrCode is a config or an internal error + ErrCode = errors.New("Case statement in code is not correct.") + // ErrNoResult is a not results error + ErrNoResult = errors.New("Result not found.") + // ErrUnavailable is a database not available error ErrUnavailable = errors.New("Database is unavailable.") ) -// Id returns the user id -func (u *User) ID() string { +// UserID returns the user id +func (u *User) UserID() string { return fmt.Sprintf("%v", u.Id) } @@ -62,15 +65,15 @@ func UserByEmail(email string) (User, error) { return result, err } -// UserIdByEmail gets user id from email -func UserIdByEmail(email string) (User, error) { +// UserIDByEmail gets user id from email +func UserIDByEmail(email string) (User, error) { result := User{} err := database.Sql.Get(&result, "SELECT id FROM user WHERE email = ? LIMIT 1", email) return result, err } // UserCreate creates user -func UserCreate(first_name, last_name, email, password string) error { - _, err := database.Sql.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", first_name, last_name, email, password) +func UserCreate(firstName, lastName, email, password string) error { + _, err := database.Sql.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", firstName, lastName, email, password) return err } diff --git a/model/user.go b/model/user.go index d5e4f52..a382ef2 100644 --- a/model/user.go +++ b/model/user.go @@ -18,44 +18,47 @@ import ( // User table contains the information for each user type User struct { - ObjectId bson.ObjectId `bson:"_id"` - Id uint32 `db:"id" bson:"id,omitempty"` // Don't use Id, use ID() instead for consistency with MongoDB - First_name string `db:"first_name" bson:"first_name"` - Last_name string `db:"last_name" bson:"last_name"` - Email string `db:"email" bson:"email"` - Password string `db:"password" bson:"password"` - Status_id uint8 `db:"status_id" bson:"status_id"` - Created_at time.Time `db:"created_at" bson:"created_at"` - Updated_at time.Time `db:"updated_at" bson:"updated_at"` - Deleted uint8 `db:"deleted" bson:"deleted"` + ObjectID bson.ObjectId `bson:"_id"` + ID uint32 `db:"id" bson:"id,omitempty"` // Don't use Id, use UserID() instead for consistency with MongoDB + FirstName string `db:"first_name" bson:"first_name"` + LastName string `db:"last_name" bson:"last_name"` + Email string `db:"email" bson:"email"` + Password string `db:"password" bson:"password"` + StatusID uint8 `db:"status_id" bson:"status_id"` + CreatedAt time.Time `db:"created_at" bson:"created_at"` + UpdatedAt time.Time `db:"updated_at" bson:"updated_at"` + Deleted uint8 `db:"deleted" bson:"deleted"` } -// User_status table contains every possible user status (active/inactive) -type User_status struct { - Id uint8 `db:"id" bson:"id"` - Status string `db:"status" bson:"status"` - Created_at time.Time `db:"created_at" bson:"created_at"` - Updated_at time.Time `db:"updated_at" bson:"updated_at"` - Deleted uint8 `db:"deleted" bson:"deleted"` +// UserStatus table contains every possible user status (active/inactive) +type UserStatus struct { + ID uint8 `db:"id" bson:"id"` + Status string `db:"status" bson:"status"` + CreatedAt time.Time `db:"created_at" bson:"created_at"` + UpdatedAt time.Time `db:"updated_at" bson:"updated_at"` + Deleted uint8 `db:"deleted" bson:"deleted"` } var ( - ErrCode = errors.New("Case statement in code is not correct.") - ErrNoResult = errors.New("Result not found.") + // ErrCode is a config or an internal error + ErrCode = errors.New("Case statement in code is not correct.") + // ErrNoResult is a not results error + ErrNoResult = errors.New("Result not found.") + // ErrUnavailable is a database not available error ErrUnavailable = errors.New("Database is unavailable.") ) -// Id returns the user id -func (u *User) ID() string { +// UserID returns the user id +func (u *User) UserID() string { r := "" switch database.ReadConfig().Type { case database.TypeMySQL: - r = fmt.Sprintf("%v", u.Id) + r = fmt.Sprintf("%v", u.ID) case database.TypeMongoDB: - r = u.ObjectId.Hex() + r = u.ObjectID.Hex() case database.TypeBolt: - r = u.ObjectId.Hex() + r = u.ObjectID.Hex() } return r @@ -78,7 +81,7 @@ func UserByEmail(email string) (User, error) { switch database.ReadConfig().Type { case database.TypeMySQL: - err = database.Sql.Get(&result, "SELECT id, password, status_id, first_name FROM user WHERE email = ? LIMIT 1", email) + err = database.SQL.Get(&result, "SELECT id, password, status_id, first_name FROM user WHERE email = ? LIMIT 1", email) case database.TypeMongoDB: if database.CheckConnection() { session := database.Mongo.Copy() @@ -101,15 +104,15 @@ func UserByEmail(email string) (User, error) { } // UserCreate creates user -func UserCreate(first_name, last_name, email, password string) error { +func UserCreate(firstName, lastName, email, password string) error { var err error now := time.Now() switch database.ReadConfig().Type { case database.TypeMySQL: - _, err = database.Sql.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", first_name, - last_name, email, password) + _, err = database.SQL.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", firstName, + lastName, email, password) case database.TypeMongoDB: if database.CheckConnection() { session := database.Mongo.Copy() @@ -117,15 +120,15 @@ func UserCreate(first_name, last_name, email, password string) error { c := session.DB(database.ReadConfig().MongoDB.Database).C("user") user := &User{ - ObjectId: bson.NewObjectId(), - First_name: first_name, - Last_name: last_name, - Email: email, - Password: password, - Status_id: 1, - Created_at: now, - Updated_at: now, - Deleted: 0, + ObjectID: bson.NewObjectId(), + FirstName: firstName, + LastName: lastName, + Email: email, + Password: password, + StatusID: 1, + CreatedAt: now, + UpdatedAt: now, + Deleted: 0, } err = c.Insert(user) } else { @@ -133,15 +136,15 @@ func UserCreate(first_name, last_name, email, password string) error { } case database.TypeBolt: user := &User{ - ObjectId: bson.NewObjectId(), - First_name: first_name, - Last_name: last_name, - Email: email, - Password: password, - Status_id: 1, - Created_at: now, - Updated_at: now, - Deleted: 0, + ObjectID: bson.NewObjectId(), + FirstName: firstName, + LastName: lastName, + Email: email, + Password: password, + StatusID: 1, + CreatedAt: now, + UpdatedAt: now, + Deleted: 0, } err = database.Update("user", user.Email, &user) diff --git a/route/middleware/httprouterwrapper/httprouterwrapper.go b/route/middleware/httprouterwrapper/httprouterwrapper.go index 729d65b..331a164 100644 --- a/route/middleware/httprouterwrapper/httprouterwrapper.go +++ b/route/middleware/httprouterwrapper/httprouterwrapper.go @@ -1,8 +1,8 @@ -// Source: http://nicolasmerouze.com/guide-routers-golang/ - -// Package middleware allows the use of http.HandlerFunc compatible funcs with julienschmidt/httprouter +// Package httprouterwrapper allows the use of http.HandlerFunc compatible funcs with julienschmidt/httprouter package httprouterwrapper +// Source: http://nicolasmerouze.com/guide-routers-golang/ + import ( "net/http" diff --git a/route/route.go b/route/route.go index eca99ac..e91843d 100644 --- a/route/route.go +++ b/route/route.go @@ -16,17 +16,17 @@ import ( "github.com/justinas/alice" ) -// Load the routes and middleware +// Load returns the routes and middleware func Load() http.Handler { return middleware(routes()) } -// Load the HTTP routes and middleware +// LoadHTTPS returns the HTTP routes and middleware func LoadHTTPS() http.Handler { return middleware(routes()) } -// Load the HTTPS routes and middleware +// LoadHTTP returns the HTTPS routes and middleware func LoadHTTP() http.Handler { return middleware(routes()) @@ -59,7 +59,7 @@ func routes() *httprouter.Router { // Home page r.GET("/", hr.Handler(alice. New(). - ThenFunc(controller.Index))) + ThenFunc(controller.IndexGET))) // Login r.GET("/login", hr.Handler(alice. @@ -70,7 +70,7 @@ func routes() *httprouter.Router { ThenFunc(controller.LoginPOST))) r.GET("/logout", hr.Handler(alice. New(). - ThenFunc(controller.Logout))) + ThenFunc(controller.LogoutGET))) // Register r.GET("/register", hr.Handler(alice. diff --git a/shared/database/database.go b/shared/database/database.go index cd10c35..46a9e05 100644 --- a/shared/database/database.go +++ b/shared/database/database.go @@ -7,30 +7,43 @@ import ( "time" "github.com/boltdb/bolt" - _ "github.com/go-sql-driver/mysql" + _ "github.com/go-sql-driver/mysql" // MySQL driver "github.com/jmoiron/sqlx" "gopkg.in/mgo.v2" ) var ( - BoltDB *bolt.DB // Bolt wrapper - Mongo *mgo.Session // Mongo wrapper - Sql *sqlx.DB // SQL wrapper - databases DatabaseInfo // Database info + // BoltDB wrapper + BoltDB *bolt.DB + // Mongo wrapper + Mongo *mgo.Session + // SQL wrapper + SQL *sqlx.DB + // Database info + databases Info ) -type DatabaseType string +// Type is the type of database from a Type* constant +type Type string const ( - TypeBolt DatabaseType = "Bolt" - TypeMongoDB DatabaseType = "MongoDB" - TypeMySQL DatabaseType = "MySQL" + // TypeBolt is BoltDB + TypeBolt Type = "Bolt" + // TypeMongoDB is MongoDB + TypeMongoDB Type = "MongoDB" + // TypeMySQL is MySQL + TypeMySQL Type = "MySQL" ) -type DatabaseInfo struct { - Type DatabaseType - MySQL MySQLInfo - Bolt BoltInfo +// Info contains the database configurations +type Info struct { + // Database type + Type Type + // MySQL info if used + MySQL MySQLInfo + // Bolt info if used + Bolt BoltInfo + // MongoDB info if used MongoDB MongoDBInfo } @@ -70,7 +83,7 @@ func DSN(ci MySQLInfo) string { } // Connect to the database -func Connect(d DatabaseInfo) { +func Connect(d Info) { var err error // Store the config @@ -79,12 +92,12 @@ func Connect(d DatabaseInfo) { switch d.Type { case TypeMySQL: // Connect to MySQL - if Sql, err = sqlx.Connect("mysql", DSN(d.MySQL)); err != nil { + if SQL, err = sqlx.Connect("mysql", DSN(d.MySQL)); err != nil { log.Println("SQL Driver Error", err) } // Check if is alive - if err = Sql.Ping(); err != nil { + if err = SQL.Ping(); err != nil { log.Println("Database Error", err) } case TypeBolt: @@ -94,7 +107,7 @@ func Connect(d DatabaseInfo) { } case TypeMongoDB: // Connect to MongoDB - if Mongo, err = mgo.DialWithTimeout(d.MongoDB.URL, 5 * time.Second); err != nil { + if Mongo, err = mgo.DialWithTimeout(d.MongoDB.URL, 5*time.Second); err != nil { log.Println("MongoDB Driver Error", err) return } @@ -112,22 +125,22 @@ func Connect(d DatabaseInfo) { } // Update makes a modification to Bolt -func Update(bucket_name string, key string, dataStruct interface{}) error { +func Update(bucketName string, key string, dataStruct interface{}) error { err := BoltDB.Update(func(tx *bolt.Tx) error { // Create the bucket - bucket, e := tx.CreateBucketIfNotExists([]byte(bucket_name)) + bucket, e := tx.CreateBucketIfNotExists([]byte(bucketName)) if e != nil { return e } // Encode the record - encoded_record, e := json.Marshal(dataStruct) + encodedRecord, e := json.Marshal(dataStruct) if e != nil { return e } // Store the record - if e = bucket.Put([]byte(key), encoded_record); e != nil { + if e = bucket.Put([]byte(key), encodedRecord); e != nil { return e } return nil @@ -136,10 +149,10 @@ func Update(bucket_name string, key string, dataStruct interface{}) error { } // View retrieves a record in Bolt -func View(bucket_name string, key string, dataStruct interface{}) error { +func View(bucketName string, key string, dataStruct interface{}) error { err := BoltDB.View(func(tx *bolt.Tx) error { // Get the bucket - b := tx.Bucket([]byte(bucket_name)) + b := tx.Bucket([]byte(bucketName)) if b == nil { return bolt.ErrBucketNotFound } @@ -176,6 +189,6 @@ func CheckConnection() bool { } // ReadConfig returns the database information -func ReadConfig() DatabaseInfo { +func ReadConfig() Info { return databases } diff --git a/shared/passhash/passhash.go b/shared/passhash/passhash.go index e226091..4535eb5 100644 --- a/shared/passhash/passhash.go +++ b/shared/passhash/passhash.go @@ -29,9 +29,9 @@ func MatchString(hash, password string) bool { err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) if err == nil { return true - } else { - return false } + + return false } // MatchBytes returns true if the hash matches the password @@ -39,7 +39,7 @@ func MatchBytes(hash, password []byte) bool { err := bcrypt.CompareHashAndPassword(hash, []byte(password)) if err == nil { return true - } else { - return false } + + return false } diff --git a/shared/recaptcha/recaptcha.go b/shared/recaptcha/recaptcha.go index 3b635d7..e33fdec 100644 --- a/shared/recaptcha/recaptcha.go +++ b/shared/recaptcha/recaptcha.go @@ -8,23 +8,23 @@ import ( ) var ( - recap RecaptchaInfo + recap Info ) -// RecaptchaInfo has the details for the Google reCAPTCHA -type RecaptchaInfo struct { +// Info has the details for the Google reCAPTCHA +type Info struct { Enabled bool Secret string SiteKey string } // Configure adds the settings for Google reCAPTCHA -func Configure(c RecaptchaInfo) { +func Configure(c Info) { recap = c } // ReadConfig returns the settings for Google reCAPTCHA -func ReadConfig() RecaptchaInfo { +func ReadConfig() Info { return recap } @@ -41,8 +41,8 @@ func Verified(r *http.Request) bool { return re.Verify(*r) } -// RecaptchaFuncMapp returns a map of functions that are usable in templates -func RecaptchaPlugin() template.FuncMap { +// Plugin returns a map of functions that are usable in templates +func Plugin() template.FuncMap { f := make(template.FuncMap) f["RECAPTCHA_SITEKEY"] = func() template.HTML { diff --git a/shared/view/view.go b/shared/view/view.go index 9f1e1ce..0970ebe 100644 --- a/shared/view/view.go +++ b/shared/view/view.go @@ -23,9 +23,13 @@ func init() { } var ( - FlashError = "alert-danger" + // FlashError is a bootstrap class + FlashError = "alert-danger" + // FlashSuccess is a bootstrap class FlashSuccess = "alert-success" - FlashNotice = "alert-info" + // FlashNotice is a bootstrap class + FlashNotice = "alert-info" + // FlashWarning is a bootstrap class FlashWarning = "alert-warning" childTemplates []string @@ -61,12 +65,12 @@ type Flash struct { Class string } -// Configure will set the view information +// Configure sets the view information func Configure(vi View) { viewInfo = vi } -// Read the configuration +// ReadConfig returns the configuration func ReadConfig() View { return viewInfo } @@ -154,7 +158,7 @@ func (v *View) AssetTimePath(s string) (string, error) { return v.PrependBaseURI(s + "?" + time), nil } -// Render a template to the screen +// RenderSingle renders a template to the writer func (v *View) RenderSingle(w http.ResponseWriter) { // Get the template collection from cache @@ -228,7 +232,7 @@ func (v *View) RenderSingle(w http.ResponseWriter) { } } -// Render a template to the screen +// Render renders a template to the writer func (v *View) Render(w http.ResponseWriter) { // Get the template collection from cache @@ -245,7 +249,7 @@ func (v *View) Render(w http.ResponseWriter) { if !ok || !viewInfo.Caching { // List of template names - templateList := make([]string, 0) + var templateList []string templateList = append(templateList, rootTemplate) templateList = append(templateList, v.Name) templateList = append(templateList, childTemplates...) @@ -337,7 +341,7 @@ func peekFlashes(w http.ResponseWriter, r *http.Request) []Flash { // Get session sess := session.Instance(r) - v := make([]Flash, 0) + var v []Flash // Get the flashes for the template if flashes := sess.Flashes(); len(flashes) > 0 {