This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/jinzhu/gorm" | ||
"github.com/vmpartner/bitmex/tools" | ||
) | ||
|
||
func Connect(login string, password string, host string, name string, ) *gorm.DB { | ||
dbLink := fmt.Sprintf("%s:%s@tcp(%s)/%s?parseTime=true", login, password, host, name) | ||
db, err := gorm.Open("mysql", dbLink) | ||
tools.CheckErr(err) | ||
db.Exec(`SET NAMES UTF8`) | ||
|
||
return db | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package database | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestConnectMaster(t *testing.T) { | ||
|
||
} | ||
|
||
func TestConnectDev(t *testing.T) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package tools | ||
|
||
import ( | ||
"os" | ||
"encoding/gob" | ||
) | ||
|
||
func CheckErr(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func WriteGob(filePath string, object interface{}) error { | ||
file, err := os.Create(filePath) | ||
if err == nil { | ||
encoder := gob.NewEncoder(file) | ||
encoder.Encode(object) | ||
} | ||
file.Close() | ||
return err | ||
} | ||
|
||
func ReadGob(filePath string, object interface{}) error { | ||
file, err := os.Open(filePath) | ||
if err == nil { | ||
decoder := gob.NewDecoder(file) | ||
err = decoder.Decode(object) | ||
} | ||
file.Close() | ||
return err | ||
} |