diff --git a/.gitignore b/.gitignore index 7d03aec378b08ad74a87ff8f5ca30374cbc1341d..d8ad6bd5253033b57502d718038fa91e2870551f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ *.a *.so -InstallLogs.txt +*.txt # Folders _obj @@ -23,4 +23,6 @@ _testmain.go *.exe *.test -*.bench \ No newline at end of file +*.bench + +vendor \ No newline at end of file diff --git a/GoGetScript.sh b/GoGetScript.sh index db1b359fe7159dc117db41ea0252a3fb7a976383..950d3f0da2ab50ca816a1ed2fcf38758110b42c5 100755 --- a/GoGetScript.sh +++ b/GoGetScript.sh @@ -5,25 +5,25 @@ NOW=$(date +"%d-%b-%Y %H:%M:%S") echo $NOW " : Installed \"github.com/allegro/bigcache\"" >> InstallLogs.txt -# echo "Installing : \"github.com/spf13/viper\"" -# go get "github.com/spf13/viper" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/spf13/viper\"" >> InstallLogs.txt +echo "Installing : \"github.com/spf13/viper\"" +go get "github.com/spf13/viper" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/spf13/viper\"" >> InstallLogs.txt -# echo "Installing : \"github.com/gocraft/dbr\"" -# go get "github.com/gocraft/dbr" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/gocraft/dbr\"" >> InstallLogs.txt +echo "Installing : \"github.com/gocraft/dbr\"" +go get "github.com/gocraft/dbr" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/gocraft/dbr\"" >> InstallLogs.txt -# echo "Installing : \"gopkg.in/mgo.v2\"" -# go get "gopkg.in/mgo.v2" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"gopkg.in/mgo.v2\"" >> InstallLogs.txt +echo "Installing : \"gopkg.in/mgo.v2\"" +go get "gopkg.in/mgo.v2" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"gopkg.in/mgo.v2\"" >> InstallLogs.txt echo "Installing : \"github.com/garyburd/redigo/redis\"" @@ -33,25 +33,25 @@ NOW=$(date +"%d-%b-%Y %H:%M:%S") echo $NOW " : Installed \"github.com/garyburd/redigo/redis\"" >> InstallLogs.txt -# echo "Installing : \"github.com/stretchr/testify/assert\"" -# go get "github.com/stretchr/testify/assert" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/stretchr/testify/assert\"" >> InstallLogs.txt +echo "Installing : \"github.com/stretchr/testify/assert\"" +go get "github.com/stretchr/testify/assert" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/stretchr/testify/assert\"" >> InstallLogs.txt -# echo "Installing : \"github.com/labstack/echo\"" -# go get "github.com/labstack/echo" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/labstack/echo\"" >> InstallLogs.txt +echo "Installing : \"github.com/labstack/echo\"" +go get "github.com/labstack/echo" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/labstack/echo\"" >> InstallLogs.txt -# echo "Installing : \"gopkg.in/mgo.v2/bson\"" -# go get "gopkg.in/mgo.v2/bson" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"gopkg.in/mgo.v2/bson\"" >> InstallLogs.txt +echo "Installing : \"gopkg.in/mgo.v2/bson\"" +go get "gopkg.in/mgo.v2/bson" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"gopkg.in/mgo.v2/bson\"" >> InstallLogs.txt echo "Installing : \"github.com/dgrijalva/jwt-go\"" @@ -61,32 +61,32 @@ NOW=$(date +"%d-%b-%Y %H:%M:%S") echo $NOW " : Installed \"github.com/dgrijalva/jwt-go\"" >> InstallLogs.txt -# echo "Installing : \"github.com/labstack/echo/middleware\"" -# go get "github.com/labstack/echo/middleware" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/labstack/echo/middleware\"" >> InstallLogs.txt +echo "Installing : \"github.com/labstack/echo/middleware\"" +go get "github.com/labstack/echo/middleware" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/labstack/echo/middleware\"" >> InstallLogs.txt -# echo "Installing : \"github.com/sirupsen/logrus\"" -# go get "github.com/sirupsen/logrus" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/sirupsen/logrus\"" >> InstallLogs.txt +echo "Installing : \"github.com/sirupsen/logrus\"" +go get "github.com/sirupsen/logrus" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/sirupsen/logrus\"" >> InstallLogs.txt -# echo "Installing : \"github.com/go-playground/locales/en\"" -# go get "github.com/go-playground/locales/en" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"github.com/go-playground/locales/en\"" >> InstallLogs.txt +echo "Installing : \"github.com/go-playground/locales/en\"" +go get "github.com/go-playground/locales/en" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"github.com/go-playground/locales/en\"" >> InstallLogs.txt -# echo "Installing : \"gopkg.in/go-playground/validator.v9\"" -# go get "gopkg.in/go-playground/validator.v9" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"gopkg.in/go-playground/validator.v9\"" >> InstallLogs.txt +echo "Installing : \"gopkg.in/go-playground/validator.v9\"" +go get "gopkg.in/go-playground/validator.v9" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"gopkg.in/go-playground/validator.v9\"" >> InstallLogs.txt echo "Installing : \"github.com/go-playground/universal-translator\"" @@ -96,17 +96,17 @@ NOW=$(date +"%d-%b-%Y %H:%M:%S") echo $NOW " : Installed \"github.com/go-playground/universal-translator\"" >> InstallLogs.txt -# echo "Installing : \"gopkg.in/go-playground/validator.v9/translations/en\"" -# go get "gopkg.in/go-playground/validator.v9/translations/en" -# echo "Done" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo $NOW " : Installed \"gopkg.in/go-playground/validator.v9/translations/en\"" >> InstallLogs.txt +echo "Installing : \"gopkg.in/go-playground/validator.v9/translations/en\"" +go get "gopkg.in/go-playground/validator.v9/translations/en" +echo "Done" +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo $NOW " : Installed \"gopkg.in/go-playground/validator.v9/translations/en\"" >> InstallLogs.txt -# echo "******************************************" -# echo "Installation complete" -# echo "******************************************" +echo "******************************************" +echo "Installation complete" +echo "******************************************" -# NOW=$(date +"%d-%b-%Y %H:%M:%S") -# echo "******************************************" >> InstallLogs.txt -# echo $NOW "Installation complete" >> InstallLogs.txt -# echo "******************************************" >> InstallLogs.txt \ No newline at end of file +NOW=$(date +"%d-%b-%Y %H:%M:%S") +echo "******************************************" >> InstallLogs.txt +echo $NOW "Installation complete" >> InstallLogs.txt +echo "******************************************" >> InstallLogs.txt \ No newline at end of file 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 7a71625a1a33116511af67524a559e87f4e50b2a..8f677db0c6e44399e9893a1bb6bb7b93271e3dd5 100644 --- a/cacheHelper.go +++ b/cacheHelper.go @@ -1,55 +1,63 @@ -package coreos - -import ( - "GolangFullStack/server/api/server/config" - "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/configHelper.go b/configHelper.go index e9a2ed71d8fc3723479ca7dbf680fe85051dbf5b..214cb1a9c4f82b00abb86157982e4f7c7d2d503e 100644 --- a/configHelper.go +++ b/configHelper.go @@ -1,27 +1,21 @@ package coreos -import ( - "fmt" - - "github.com/spf13/viper" -) - //InitViper function to initialize viper func InitViper() { - viper.SetConfigName("config") // name of config file (without extension) - viper.AddConfigPath(".") // optionally look for config in the working directory - err := viper.ReadInConfig() - // Find and read the config file - if err != nil { // Handle errors reading the config file - panic(fmt.Errorf("Fatal error config file %s ", err)) - } + // viper.SetConfigName("config") // name of config file (without extension) + // viper.AddConfigPath(".") // optionally look for config in the working directory + // err := viper.ReadInConfig() + // // Find and read the config file + // if err != nil { // Handle errors reading the config file + // panic(fmt.Errorf("Fatal error config file %s ", err)) + // } } //GetConfig method to get configs from config file func GetConfig(keyName string) string { - keyValue := viper.GetString(keyName) - - return keyValue + // keyValue := viper.GetString(keyName) + // return keyValue + return "" } 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 225499b1d19d9be441e5ec8992dd9989214e6793..7a5ff983cc3ecd8b63652bba79d1d8e6a377606b 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,5 +1,6 @@ package: coreospackage import: +- package: GolangFullStack/server/api/server/config - package: github.com/allegro/bigcache - package: github.com/dgrijalva/jwt-go version: ^3.0.0 @@ -16,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