From d2cb40d7de27c9389d8e9112716771524f450459 Mon Sep 17 00:00:00 2001 From: Rachid Lafriakh Date: Sun, 3 Feb 2019 03:36:28 +0100 Subject: [PATCH] remove unused code and update go.mod --- README.md | 1 + config/config.go | 147 ------------------ config/config_test.go | 25 --- config/testdata/environments/development.yaml | 0 config/testdata/environments/production.yaml | 0 config/testdata/environments/test.yaml | 0 config/testdata/session.yaml | 1 - database/mongo/mongo.go | 50 ------ database/mysql/mysql.go | 44 ------ go.mod | 8 - go.sum | 45 +----- plugins/plugins.go | 4 + session/file_handler.go | 6 +- session/store.go | 8 +- upload/upload.go | 4 +- 15 files changed, 17 insertions(+), 326 deletions(-) delete mode 100644 config/config.go delete mode 100644 config/config_test.go delete mode 100644 config/testdata/environments/development.yaml delete mode 100644 config/testdata/environments/production.yaml delete mode 100644 config/testdata/environments/test.yaml delete mode 100644 config/testdata/session.yaml delete mode 100644 database/mongo/mongo.go delete mode 100644 database/mysql/mysql.go create mode 100644 plugins/plugins.go diff --git a/README.md b/README.md index 237ef56..9621625 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Kira + Kira micro framework diff --git a/config/config.go b/config/config.go deleted file mode 100644 index b2abfa4..0000000 --- a/config/config.go +++ /dev/null @@ -1,147 +0,0 @@ -package config - -import ( - "bytes" - "errors" - "io/ioutil" - "path/filepath" - - "github.com/go-kira/kog" - - yaml "gopkg.in/yaml.v2" -) - -var errInvalidEnv = errors.New("invalid environment, use only: development, production, test") - -// DefaultPath to the configs folder. -var DefaultPath = "./config/" - -// DefaultVariablesPath enviroments path. -var DefaultVariablesPath = "./config/environments/" - -// Env type -type Env int - -const ( - // Development enviroment - Development Env = iota - // Production enviroment - Production - // Test enviroment - Test -) - -var envStrings = map[string]Env{ - "development": Development, - "production": Production, - "test": Test, -} -var envNames = [...]string{ - Production: "production", - Development: "development", - Test: "test", -} - -// to store all config files -var globalData map[string]interface{} - -// New return Config instance -func New(env string) map[string]interface{} { - // first check if the env supported. - if _, ok := envStrings[env]; !ok { - kog.Panic(errInvalidEnv) - } - - // load configs - configs := load(env) - - // return configs - if configs == nil { - // panic here - return globalData - } - // panic if there an error. - kog.Panic(configs) - - return globalData -} - -// Load config file data -func load(env string) error { - var buf bytes.Buffer - - // to store all config files - var files []string - - // first get all config files - configs, err := filepath.Glob(DefaultPath + "*.yaml") - if err != nil { - return err - } - files = append(files, configs...) - - // add env file to the config files. - // this will change any config value. - if env != "" { - files = append(files, DefaultVariablesPath+env+".yaml") - } - - // loop throw all - for _, config := range files { - // read file - data, err := ioutil.ReadFile(config) - if err != nil { - return err - } - - buf.Write(data) - buf.WriteString("\n") // add new line to the end of the file - } - - // Unmarshal toml data - yaml.Unmarshal(buf.Bytes(), &globalData) - - return nil -} - -// Get ... -func Get(key string) interface{} { - return globalData[key] -} - -// GetDefault return value by key, if the value empty set a default value. -func GetDefault(key string, def interface{}) interface{} { - val := globalData[key] - if val == nil { - return def - } - - return val -} - -// GetString - return config as string type. -func GetString(key string) string { - if globalData[key] == nil { - return "" - } - - return globalData[key].(string) -} - -// GetInt - return config as int type. -func GetInt(key string) int { - if globalData[key] == nil { - return 0 - } - - return globalData[key].(int) -} - -// GetBool - return config as int type. -func GetBool(key string) bool { - if globalData[key] == nil { - return false - } - - return globalData[key].(bool) -} diff --git a/config/config_test.go b/config/config_test.go deleted file mode 100644 index 73069dd..0000000 --- a/config/config_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package config - -import ( - "testing" -) - -func TestLoad(t *testing.T) { - DefaultPath = "./testdata" - DefaultVariablesPath = "./testdata/enviroments" - - New("production") - t.Fail() -} - -func TestGetDefault(t *testing.T) { - DefaultPath = "./testdata/" - DefaultVariablesPath = "./testdata/environments/" - - New("development") - def := GetDefault("SESSION_NAMEe", "default") - - if def != "default" { - t.Error("the value not 'default'") - } -} diff --git a/config/testdata/environments/development.yaml b/config/testdata/environments/development.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/config/testdata/environments/production.yaml b/config/testdata/environments/production.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/config/testdata/environments/test.yaml b/config/testdata/environments/test.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/config/testdata/session.yaml b/config/testdata/session.yaml deleted file mode 100644 index 203296f..0000000 --- a/config/testdata/session.yaml +++ /dev/null @@ -1 +0,0 @@ -SESSION_NAME: kira \ No newline at end of file diff --git a/database/mongo/mongo.go b/database/mongo/mongo.go deleted file mode 100644 index 4efb398..0000000 --- a/database/mongo/mongo.go +++ /dev/null @@ -1,50 +0,0 @@ -package mongo - -import ( - "github.com/Lafriakh/log" - "github.com/go-kira/kon" - mgo "gopkg.in/mgo.v2" -) - -// Mongo - global mongo session. -var Mongo *mgo.Session - -// WithMongo - Open return new mongodb session -func WithMongo(configs *kon.Kon) *mgo.Session { - info := mgo.DialInfo{ - Addrs: []string{configs.GetString("DB_HOST")}, - Database: configs.GetString("DB_DATABASE"), - Username: configs.GetString("DB_USERNAME"), - Password: configs.GetString("DB_PASSWORD"), - } - - // Connect - session, err := mgo.DialWithInfo(&info) - if err != nil { - log.Panic(err) - } - // Optional. Switch the Session to a monotonic behavior. - session.SetMode(mgo.Monotonic, true) - - // append session to global variable. - Mongo = session - - // return mongo session. - return session -} - -// Insert - to insert data into collection. -func Insert(configs *kon.Kon, name string, docs ...interface{}) error { - err := Mongo.DB(configs.GetString("DB_DATABASE")).C(name).Insert(docs...) - return err -} - -// Database - return mongo database. -func Database(configs *kon.Kon, database string) *mgo.Database { - return Mongo.DB(configs.GetString("DB_DATABASE")) -} - -// C - return mongo collection. -func C(configs *kon.Kon, name string) *mgo.Collection { - return Mongo.DB(configs.GetString("DB_DATABASE")).C(name) -} diff --git a/database/mysql/mysql.go b/database/mysql/mysql.go deleted file mode 100644 index ba6cead..0000000 --- a/database/mysql/mysql.go +++ /dev/null @@ -1,44 +0,0 @@ -package kira - -import ( - "database/sql" - "fmt" - - _ "github.com/go-sql-driver/mysql" - - "github.com/Lafriakh/config" - "github.com/Lafriakh/log" -) - -// WithMysql - open an mysql connection. -func (a *App) WithMysql() { - var err error - - options := fmt.Sprintf("%s:%s@%s(%s:%d)/%s?%s", - config.GetString("DB_USERNAME"), - config.GetString("DB_PASSWORD"), - config.GetDefault("DB_PROTOCOL", "tcp").(string), - config.GetString("DB_HOST"), - config.GetInt("DB_PORT"), - config.GetString("DB_DATABASE"), - config.GetDefault("DB_PARAMS", "charset=utf8&parseTime=true").(string), - ) - - // log.Debug(options) - - a.DB, err = sql.Open("mysql", options) - if err != nil { - log.Panic(err.Error()) - } - - // Open doesn't open a connection. Validate DSN data: - err = a.DB.Ping() - if err != nil { - log.Panic(err) - } -} - -// CloseMysql - for close mysql connection -func (a *App) CloseMysql() { - a.DB.Close() -} diff --git a/go.mod b/go.mod index f95e541..68a8be9 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,10 @@ module github.com/go-kira/kira require ( - github.com/Lafriakh/config v0.0.0-20171223003722-dc734f141b64 - github.com/Lafriakh/kira v0.0.0-20181021152015-0e026c0c4b55 - github.com/Lafriakh/log v0.0.0-20180527032428-2ebd3a914d94 github.com/go-kira/kog v0.0.0 github.com/go-kira/kon v0.0.0 - github.com/go-sql-driver/mysql v1.4.1 github.com/google/uuid v1.1.0 github.com/gorilla/mux v1.7.0 golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 - golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce gopkg.in/natefinch/lumberjack.v2 v2.0.0 - gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index fc21353..3035dda 100644 --- a/go.sum +++ b/go.sum @@ -1,58 +1,21 @@ -github.com/Lafriakh/config v0.0.0-20171223003722-dc734f141b64 h1:vwP8f22KiiAVoydDOdi/2iAvUB6De62UbuUrnv4AjEE= -github.com/Lafriakh/config v0.0.0-20171223003722-dc734f141b64/go.mod h1:QG+JPifM/d3A7SEPexTtVMhdEOsI8+SgodF0HpXaorg= -github.com/Lafriakh/kira v0.0.0-20181021152015-0e026c0c4b55 h1:OrCs/XTXnUF5biZLWP5i+lpbCsJlUWQqkUPXztH32nU= -github.com/Lafriakh/kira v0.0.0-20181021152015-0e026c0c4b55/go.mod h1:aunVy1d+3IdNOAQXp/04vmjrpGiKesya5uVciBpr6lk= -github.com/Lafriakh/log v0.0.0-20180527032428-2ebd3a914d94 h1:V0Kjl3uKCY87RWW4hyGyVH2LwZ8SEqn9y1Uth/A2E90= -github.com/Lafriakh/log v0.0.0-20180527032428-2ebd3a914d94/go.mod h1:c6IliimJtYK78Ivh9MInHqaZf/+8RAz+cgCoz59Q98s= -github.com/go-kira/kog v0.0.0-20180917154418-0a9eb8cd3237 h1:5+TZMjl1sVLP6VhdhE7dES0RKkb4LF6txlADWHTUWEw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/go-kira/kog v0.0.0-20180917154418-0a9eb8cd3237/go.mod h1:zqGZJHidG6U0e34KJBAtij6d9AW+/dFynky0vyd/H60= -github.com/go-kira/kog v0.0.0-20181016231056-fad3a48d043b h1:tgs4F63/h5qzB/3IQsNFJUDomXEAW3ZE038pzaFbzxo= -github.com/go-kira/kog v0.0.0-20181016231056-fad3a48d043b/go.mod h1:zqGZJHidG6U0e34KJBAtij6d9AW+/dFynky0vyd/H60= github.com/go-kira/kog v0.0.0 h1:DAzDjiKi2Trk89MgfY17wTh/c4LN3IlgPLc4uV87Woc= github.com/go-kira/kog v0.0.0/go.mod h1:zqGZJHidG6U0e34KJBAtij6d9AW+/dFynky0vyd/H60= -github.com/go-kira/kon v0.0.0-20181013165914-ab8946a5c597 h1:DxYN0WfRs7F+HEGMaiMXMSKWZNxnqTqNzvfFBt8ZjDE= -github.com/go-kira/kon v0.0.0-20181013165914-ab8946a5c597/go.mod h1:cwFD8HLwUTk0Jr6PZA1Gx2eylCmjVZV7JFs3EqKITkQ= -github.com/go-kira/kon v0.0.0-20181013202125-fb269f764192 h1:Z0spGbfYQrIPcOze6J6bJhtZ5Zpm5WihQzUBYVG/j/I= -github.com/go-kira/kon v0.0.0-20181013202125-fb269f764192/go.mod h1:cwFD8HLwUTk0Jr6PZA1Gx2eylCmjVZV7JFs3EqKITkQ= -github.com/go-kira/kon v0.0.0-20181014225737-21fb29f35f12 h1:iCfpjGUByC5ELrFKtooY704XcIAu+owhFFcY1WvtDYo= -github.com/go-kira/kon v0.0.0-20181014225737-21fb29f35f12/go.mod h1:cwFD8HLwUTk0Jr6PZA1Gx2eylCmjVZV7JFs3EqKITkQ= -github.com/go-kira/kon v0.0.0-20181103221750-93ec2d6d8e0a h1:Ll6lqWSM3LwPw+UUwDimpbFe3+JugBzT2YhM3SBMVw4= -github.com/go-kira/kon v0.0.0-20181103221750-93ec2d6d8e0a/go.mod h1:pU4cVTPg71Avt9Ue9lcHjJGCHPa9/5fCKaJcC5s7/z4= -github.com/go-kira/kon v0.0.0-20181103222844-9c2485df6f24 h1:djJ7reNlRxOO8sEe++OZcwFZB60hS1mq8Wr5Knw+qDk= -github.com/go-kira/kon v0.0.0-20181103222844-9c2485df6f24/go.mod h1:pU4cVTPg71Avt9Ue9lcHjJGCHPa9/5fCKaJcC5s7/z4= github.com/go-kira/kon v0.0.0 h1:ZBVoiEgFDTxKxGmV+6NY/RJozVGdiQSCUesbn1UO6aU= github.com/go-kira/kon v0.0.0/go.mod h1:pU4cVTPg71Avt9Ue9lcHjJGCHPa9/5fCKaJcC5s7/z4= -github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= -github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490 h1:va0qYsIOza3Nlf2IncFyOql4/3XUq3vfge/Ad64bhlM= -golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e h1:IzypfodbhbnViNUO/MEh0FzCUooG97cIGfdggUrUSyU= -golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= -golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 h1:MQ/ZZiDsUapFFiMS+vzwXkCTeEKaum+Do5rINYJDmxc= golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181017193950-04a2e542c03f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc h1:ZMCWScCvS2fUVFw8LOpxyUUW5qiviqr4Dg5NdjLeiLU= -golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU= -gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= diff --git a/plugins/plugins.go b/plugins/plugins.go new file mode 100644 index 0000000..e0fd976 --- /dev/null +++ b/plugins/plugins.go @@ -0,0 +1,4 @@ +package plugins + +// TODO +// - Plugin system: Like caddy do. diff --git a/session/file_handler.go b/session/file_handler.go index 7b71d20..c075df8 100644 --- a/session/file_handler.go +++ b/session/file_handler.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/Lafriakh/log" + "github.com/go-kira/kog" ) // FileHandler ... @@ -98,8 +98,6 @@ func (f *FileHandler) GC() { return nil }); err != nil { - log.WithContext(log.Fields{ - "files": err, - }).Error("session garbage collecting") + kog.Error("session garbage collecting") } } diff --git a/session/store.go b/session/store.go index 4db5b6d..a049633 100644 --- a/session/store.go +++ b/session/store.go @@ -1,7 +1,7 @@ package session import ( - "github.com/Lafriakh/log" + "github.com/go-kira/kog" "github.com/google/uuid" ) @@ -36,7 +36,7 @@ func (s *Store) loadSession() { func (s *Store) ReadFromHandler() SKV { readedData, err := s.Handler.Read(s.GetID()) if err != nil { - log.Panic(err) + kog.Panic(err) return nil } @@ -51,7 +51,7 @@ func (s *Store) ReadFromHandler() SKV { // decode the session data err = DecodeGob(readedData, &data) if err != nil { - log.Errorf("session decode: %v", err) + kog.Errorf("session decode: %v", err) return make(SKV) } @@ -80,7 +80,7 @@ func (s *Store) Save() { // encode the data from the handler encData, err := EncodeGob(s.Values) if err != nil { - log.Panic(err) + kog.Panic(err) } s.Handler.Write(s.GetID(), encData) diff --git a/upload/upload.go b/upload/upload.go index bd91495..367f3f3 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -9,8 +9,8 @@ import ( "os" "path/filepath" - "github.com/Lafriakh/kira" - "github.com/Lafriakh/kira/helpers" + "github.com/go-kira/kira" + "github.com/go-kira/kira/helpers" "github.com/go-kira/kog" "github.com/go-kira/kon" )