-
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.
Commit by Andy.Zhang Email: [email protected]
- Loading branch information
1 parent
7985d7e
commit 20e5c43
Showing
14 changed files
with
269 additions
and
91 deletions.
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
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,53 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/andy-zhangtao/shadow-rest/shadowsocks/util" | ||
|
||
mgo "gopkg.in/mgo.v2" | ||
) | ||
|
||
var Session *mgo.Session | ||
|
||
func init() { | ||
log.Println("==================") | ||
var err error | ||
if Session == nil { | ||
login := &mgo.DialInfo{ | ||
Addrs: []string{os.Getenv(util.MONGOURL)}, | ||
Timeout: 3600 * time.Second, | ||
Database: os.Getenv(util.MONGODB), | ||
Username: os.Getenv(util.USERNAME), | ||
Password: os.Getenv(util.PASSWORD), | ||
} | ||
|
||
// log.Printf("Connectting mongodb,env: [%v] host:[%s] db:[%s] \n", login.Addrs, login.Database, os.Environ()) | ||
Session, err = mgo.DialWithInfo(login) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
|
||
if err := Session.Ping(); err == nil { | ||
log.Printf("MONGO CONNECT SUCCESS! [%s]\n", Session.LiveServers()) | ||
} else { | ||
log.Printf("MONGO CONNECT FAILED!! [%s] Error Info [%s]\n", os.Getenv(util.MONGOURL), err.Error()) | ||
} | ||
|
||
} | ||
} | ||
|
||
func GetMongo() *mgo.Session { | ||
|
||
Session.Refresh() | ||
session := Session.Clone() | ||
if session == nil { | ||
fmt.Println("MONGODB SESSION IS NIL!!") | ||
return nil | ||
} | ||
|
||
return session | ||
} |
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
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
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
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
Oops, something went wrong.