Skip to content

Commit

Permalink
Added go lint comments in daos
Browse files Browse the repository at this point in the history
  • Loading branch information
rv404674 committed Jun 11, 2020
1 parent dd9853a commit 38ff054
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions daos/mainDao.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx"
)

//DB_NAME - the db name
var DB_NAME string

//COLLECTION1_NAME - first collection name
var COLLECTION1_NAME string

//COLLECTION2_NAME - second collection name
var COLLECTION2_NAME string
var client *mongo.Client

Expand Down Expand Up @@ -66,7 +71,7 @@ func init() {
log.Println("IndexName", indexName)
}

// this one inserts in "shortened_url" connections
// InsertInShortenedUrl - this one inserts in "shortened_url" connections
// this is using call by value i.e creating copy of urlModel everytime,
// if json is large, try to prevent this
func InsertInShortenedUrl(urlModel model.UrlModel) {
Expand All @@ -81,7 +86,7 @@ func InsertInShortenedUrl(urlModel model.UrlModel) {
log.Println("InsertedId", insertResult.InsertedID)
}

// has indexing on uniqueid field
// GetUrl - has indexing on uniqueid field
// perform find on 'shortened_url' collections
func GetUrl(inputUniqueId int) models.UrlModel {
collection := client.Database(DB_NAME).Collection(COLLECTION1_NAME)
Expand All @@ -97,7 +102,7 @@ func GetUrl(inputUniqueId int) models.UrlModel {
return result
}

// Clear the expired entries from the main "shortened_url" mongo collection
// CleanDb - Clear the expired entries from the main "shortened_url" mongo collection
func CleanDb(uid int) {
collection := client.Database(DB_NAME).Collection(COLLECTION1_NAME)
filter := bson.D{primitive.E{Key: "uniqueid", Value: uid}}
Expand All @@ -111,7 +116,7 @@ func CleanDb(uid int) {
log.Println("**Deleted " + strconv.FormatInt(deleteResult.DeletedCount, 10) + " documents ")
}

// update counter field in second collections - incrementer
// GetCounterValue - update counter field in second collections - incrementer
// also there will be an already existing value in db (i.e counter will start from)- 10000
// { "_id" : ObjectId("5e9b7c0e7b3a8740a2f828c4"), "uniqueid" : "counter", "value" : 10000 }
func GetCounterValue() int {
Expand All @@ -130,6 +135,7 @@ func GetCounterValue() int {
return result.Value
}

// UpdateCounter - update the counter value by 1
func UpdateCounter() {
collection := client.Database(DB_NAME).Collection(COLLECTION2_NAME)
filter := bson.D{primitive.E{Key: "uniqueid", Value: "counter"}}
Expand All @@ -150,7 +156,7 @@ func UpdateCounter() {

}

// will be used by CronService for db purging
// GetAll - will be used by CronService for db purging
func GetAll() *mongo.Cursor {
collection := client.Database(DB_NAME).Collection(COLLECTION1_NAME)

Expand Down
2 changes: 1 addition & 1 deletion middlewares/basicMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

//Simple middleware - just for printing
// Basic middleware - just for printing
func BasicMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 38ff054

Please sign in to comment.