本文整理匯總了Golang中github.com/dancannon/gorethink.Session.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Close方法的具體用法?Golang Session.Close怎麽用?Golang Session.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dancannon/gorethink.Session
的用法示例。
在下文中一共展示了Session.Close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Load config file
config := Config{}
var data, err = ioutil.ReadFile("config.yml")
err = yaml.Unmarshal([]byte(data), &config)
if err != nil {
log.Fatalf("error: %v", err)
}
// Establish connection to DB
var session *r.Session
session, err = r.Connect(r.ConnectOpts{
Address: config.DatabaseURI,
})
if err != nil {
log.Fatalln(err.Error())
}
bootstrapDB(session, config)
defer session.Close()
log.Println("Connected")
// Instantiate DAOs
userDAO := UserDAO{DAO{Session: session}}
postDAO := PostDAO{DAO{Session: session}}
sessionDAO := SessionDAO{DAO{Session: session}}
// Instantiate Controllers
apiController := APIController{
Controller{Session: session},
userDAO,
postDAO,
sessionDAO,
}
goji.Get("/", apiController.Index)
goji.Post("/post", apiController.CreatePost)
goji.Get("/post/:id", apiController.GetPost)
goji.Serve()
}
示例2: killSession
//killSession disconnects from the database
func killSession(session *r.Session) {
session.Close()
}
示例3: TestTravelPlanning
func TestTravelPlanning(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "TravelPlanning Suite")
}
var _ = BeforeSuite(func() {
testConn = NewDBSession(database)
})
var _ = AfterSuite(func() {
_, err := r.DBDrop(database).RunWrite(testConn)
if err != nil {
log.Print(err)
}
testConn.Close()
})
type resultToken struct {
TokenString string `json:"token"`
}
func Login() string {
APIRequest("/login", "POST", loginCredentials, "")
token := resultToken{}
json.Unmarshal(Response.Body.Bytes(), &token)
return token.TokenString
}