diff --git a/InstallLogs.txt b/InstallLogs.txt index 29f22e388e430975ca375ebb2d7766f9d930493f..802055d6139ed8e5c16c6967967f10f1c03eb598 100644 --- a/InstallLogs.txt +++ b/InstallLogs.txt @@ -10,3 +10,7 @@ 20-Jun-2017 12:37:47 : Installed "github.com/labstack/echo/middleware" 20-Jun-2017 12:39:04 : Installed "github.com/sirupsen/logrus" 20-Jun-2017 12:53:39 : Installed "github.com/allegro/bigcache" +22-Jun-2017 13:45:25 : Installed "github.com/allegro/bigcache" +22-Jun-2017 13:45:26 : Installed "github.com/garyburd/redigo/redis" +22-Jun-2017 13:45:26 : Installed "github.com/dgrijalva/jwt-go" +22-Jun-2017 13:45:53 : Installed "github.com/go-playground/universal-translator" diff --git a/cacheHelper.go b/cacheHelper.go index 0200bc27651293373e216ef15fa0b72277157ea3..8f677db0c6e44399e9893a1bb6bb7b93271e3dd5 100644 --- a/cacheHelper.go +++ b/cacheHelper.go @@ -1,54 +1,63 @@ -package coreos - -import ( - "fmt" - "time" - - "github.com/allegro/bigcache" -) - -var bigcacheConfig = bigcache.Config{ - // number of shards (must be a power of 2) - // Shards: 4096, - // Shards: config.BIGCACHEShards, - // // time after which entry can be evicted - // LifeWindow: config.BIGCACHELifeWindow * time.Hour, - // // rps * lifeWindow, used only in initial memory allocation - // MaxEntriesInWindow: 1000 * 10 * 60, - // // MaxEntriesInWindow: 10, - // // max entry size in bytes, used only in initial memory allocation - // MaxEntrySize: config.BIGCACHEMaxEntrySize, - // // prints information about additional memory allocation - // Verbose: config.BIGCACHEVerbose, - // // cache will not allocate more memory than this limit, value in MB - // // if value is reached then the oldest entries can be overridden for the new ones - // // 0 value means no size limit - // HardMaxCacheSize: config.BIGCACHEHardMaxCacheSize, - // callback fired when the oldest entry is removed because of its - // expiration time or no space left for the new entry. Default value is nil which - // means no callback and it prevents from unwrapping the oldest entry. - OnRemove: nil, -} - -var cache, initErr = bigcache.NewBigCache(bigcacheConfig) - -//GetValue GetValue -func GetValue(key string) ([]byte, error) { - return cache.Get(key) -} - -//SetValue SetValue -func SetValue(key string, value []byte) { - cache.Set(key, value) -} - -//GetLength GetLength -func GetLength() int { - return cache.Len() -} - -//Callback function executed when cache element is removed. -//Executed only when onRemove of cache config poting to this function -func onRemove(key string, entry []byte) { - fmt.Println(key + " removed at " + time.Now().String()) -} +package coreos + +import ( + "fmt" + "time" + + "github.com/allegro/bigcache" +) + + +const ( + BIGCACHEShards=8 + BIGCACHEMaxEntrySize=1024 + BIGCACHEVerbose=true + BIGCACHEHardMaxCacheSize=0 + BIGCACHEMaxEntriesInWindow=1000 10 60 + BIGCACHELifeWindow=2 +) +var bigcacheConfig = bigcache.Config{ + // number of shards (must be a power of 2) + // Shards: 4096, + Shards: BIGCACHEShards, + // time after which entry can be evicted + LifeWindow: BIGCACHELifeWindow * time.Hour, + // rps * lifeWindow, used only in initial memory allocation + MaxEntriesInWindow: 1000 * 10 * 60, + // MaxEntriesInWindow: 10, + // max entry size in bytes, used only in initial memory allocation + MaxEntrySize: BIGCACHEMaxEntrySize, + // prints information about additional memory allocation + Verbose: BIGCACHEVerbose, + // cache will not allocate more memory than this limit, value in MB + // if value is reached then the oldest entries can be overridden for the new ones + // 0 value means no size limit + HardMaxCacheSize: BIGCACHEHardMaxCacheSize, + // callback fired when the oldest entry is removed because of its + // expiration time or no space left for the new entry. Default value is nil which + // means no callback and it prevents from unwrapping the oldest entry. + OnRemove: nil, +} + +var cache, initErr = bigcache.NewBigCache(bigcacheConfig) + +//GetValue GetValue +func GetValue(key string) ([]byte, error) { + return cache.Get(key) +} + +//SetValue SetValue +func SetValue(key string, value []byte) { + cache.Set(key, value) +} + +//GetLength GetLength +func GetLength() int { + return cache.Len() +} + +//Callback function executed when cache element is removed. +//Executed only when onRemove of cache config poting to this function +func onRemove(key string, entry []byte) { + fmt.Println(key + " removed at " + time.Now().String()) +} \ No newline at end of file diff --git a/DALMySQL.go b/dalMySQL.go similarity index 82% rename from DALMySQL.go rename to dalMySQL.go index c725f5d4ecc191274fef39e0fa88a6b798077462..3cd006ea59e26c60fe85f7d154e891bbcbc0b9f0 100644 --- a/DALMySQL.go +++ b/dalMySQL.go @@ -3,8 +3,6 @@ package coreos import ( "sync" - "GolangFullStack/server/api/server/config" - "github.com/gocraft/dbr" ) @@ -16,7 +14,7 @@ var sqlOnce sync.Once func GetSQLConnection() (*dbr.Connection, error) { sqlOnce.Do(func() { // create a connection db(e.g. "postgres", "mysql", or "sqlite3") - connection, _ := dbr.Open("mysql", config.MysqlDSN, nil) + connection, _ := dbr.Open("mysql", GetConfig("MysqlDSN"), nil) // connection.SetMaxIdleConns(10) // connection.SetMaxOpenConns(5) diff --git a/DALNoSQL.go b/dalNoSQL.go similarity index 86% rename from DALNoSQL.go rename to dalNoSQL.go index a6e374accfb13000b5913f3f6870a761affa0d7c..1b309258afa7398cd5fc8339cc375a327496df2b 100644 --- a/DALNoSQL.go +++ b/dalNoSQL.go @@ -1,7 +1,6 @@ package coreos import ( - "GolangFullStack/server/api/server/config" "fmt" "sync" @@ -15,12 +14,12 @@ var once sync.Once func GetMongoConnection() *mgo.Session { once.Do(func() { Host := []string{ - config.MONGODSN, + GetConfig("MONGODSN"), } const ( Username = "" Password = "" - Database = config.DBNAME + Database = GetConfig("DBNAME") ) session, err := mgo.DialWithInfo(&mgo.DialInfo{ diff --git a/DALRedis.go b/dalRedis.go similarity index 69% rename from DALRedis.go rename to dalRedis.go index f4b876e38be3f13855a089c38302d23c49876506..a80ba700d6c43bf0d7477216b4f82c47d1e5dc1e 100644 --- a/DALRedis.go +++ b/dalRedis.go @@ -1,8 +1,6 @@ package coreos import ( - "GolangFullStack/server/api/server/config" - "github.com/garyburd/redigo/redis" ) @@ -13,7 +11,7 @@ func GetWorkPool() *redis.Pool { MaxIdle: 5, Wait: true, Dial: func() (redis.Conn, error) { - return redis.Dial("tcp", config.REDISDSN, redis.DialDatabase(3)) + return redis.Dial("tcp", GetConfig("REDISDSN"), redis.DialDatabase(3)) }, } return redisPool diff --git a/DataConvertor.go b/dataConvertor.go similarity index 100% rename from DataConvertor.go rename to dataConvertor.go diff --git a/EchoHelper.go b/echoHelper.go similarity index 100% rename from EchoHelper.go rename to echoHelper.go diff --git a/glide.yaml b/glide.yaml index 01eea14faac1cfc181df2536e21c042df2b9dd30..7a5ff983cc3ecd8b63652bba79d1d8e6a377606b 100644 --- a/glide.yaml +++ b/glide.yaml @@ -17,7 +17,7 @@ import: - package: github.com/gocraft/dbr version: ^2.1.0 - package: github.com/labstack/echo - version: ^3.2.0 + version: ^3.2.1 subpackages: - middleware - package: github.com/sirupsen/logrus diff --git a/loggingHelper.go b/loggingHelper.go index 594de71d630b2e886008af5137f52525223f458d..dcfae54cd3ef0a29f0ba643a4061baa63153376f 100644 --- a/loggingHelper.go +++ b/loggingHelper.go @@ -42,7 +42,7 @@ func Error(message string) { logger.Error(message) } -//Panic Panic +//Panic Panic func Panic(message string) { logger.Panic(message) } diff --git a/smsHelper.go b/smsHelper.go index e8517554634091414c18a5047623ed300d676320..3a0908c46700db755ac32e218c6703611b371fb6 100644 --- a/smsHelper.go +++ b/smsHelper.go @@ -1,7 +1,6 @@ package coreos import ( - "GolangFullStack/server/api/server/config" "fmt" "io/ioutil" "log" @@ -21,7 +20,7 @@ type SMS struct { // SendSMS : send SMS Service func SendSMS(smsObject SMS) error { var postURL string - postURL = config.SMSAPIURL + "?UserName=" + smsObject.UserName + "&password=" + smsObject.Password + "&MobileNo=" + smsObject.MobileNumber + "&SenderID=" + smsObject.SenderID + "&CDMAHeader=" + smsObject.CDMAHeader + "&Message=" + url.QueryEscape(smsObject.Message) + postURL = GetConfig("SMSAPIURL") + "?UserName=" + smsObject.UserName + "&password=" + smsObject.Password + "&MobileNo=" + smsObject.MobileNumber + "&SenderID=" + smsObject.SenderID + "&CDMAHeader=" + smsObject.CDMAHeader + "&Message=" + url.QueryEscape(smsObject.Message) // fmt.Println(postURL) resp, err := http.Get(postURL) if err != nil { diff --git a/validationHelper.go b/validationHelper.go index 449466cab5bab1059bece630653ea801257352b5..74b785cf45268edb088fac46638c891ab1595fc9 100644 --- a/validationHelper.go +++ b/validationHelper.go @@ -2,7 +2,6 @@ package coreos import ( "github.com/go-playground/locales/en" - "gopkg.in/go-playground/validator.v9" ut "github.com/go-playground/universal-translator" en_translations "gopkg.in/go-playground/validator.v9/translations/en" @@ -46,7 +45,7 @@ func Validate(s interface{}) map[string]string { for _, e := range errs { // can translate each error one at a time. customErrs[e.Namespace()] = e.Translate(trans) - + } return customErrs