• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gorethink.Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/dancannon/gorethink.Session的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Session类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	config := a.NewConfig("config.gcfg")
	echo := echo.New()
	s := slack.New(config.Slack.Token)

	var session *r.Session

	session, err := r.Connect(r.ConnectOpts{
		Address:  fmt.Sprint(config.Database.URL, ":", config.Database.Port),
		Database: config.Database.Name,
		MaxIdle:  10,
		MaxOpen:  10,
	})
	if err != nil {
		log.Fatalln(err.Error())
	}
	session.SetMaxOpenConns(5)

	r.DBCreate(config.Database.Name).Exec(session)
	if err != nil {
		log.Println(err)
	}

	_, err = r.DB(config.Database.Name).TableCreate("quotes").RunWrite(session)
	if err != nil {
		fmt.Print(err)
	}
	_, err = r.DB(config.Database.Name).TableCreate("activities").RunWrite(session)
	if err != nil {
		fmt.Print(err)
	}

	// Middleware
	echo.Use(mw.Logger())
	echo.Use(mw.Recover())

	appcontext := &a.AppContext{
		Slack:  s,
		Config: config,
		Storage: &storage.Storage{
			Name:    "quotes",
			URL:     "192.168.10.10",
			Session: session,
		},
	}

	go appcontext.Monitor()

	//Routes
	a.Route(echo, appcontext)

	addr := fmt.Sprintf(":%d", config.App.Port)
	log.Printf("Starting server on: %s", addr)
	echo.Run(addr)
}
开发者ID:wvdeutekom,项目名称:GoQuotes,代码行数:56,代码来源:main.go


示例2: 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()

}
开发者ID:jaydubbyasee,项目名称:seemus,代码行数:45,代码来源:server.go


示例3: seedRethinkdbChecks

func seedRethinkdbChecks(s *r.Session) error {
	r.DB("alerts").TableCreate("checks").RunWrite(s)

	data := []*Check{
		&Check{
			Id:          "elasticsearch-es_heap",
			Type:        "elasticsearch",
			Name:        "es_heap",
			Level:       1,
			Title:       "Elasticsearch Heap",
			Description: "total heap usage by an elasticsearch node",
		},
		&Check{
			Id:          "elasticsearch-es_cluster_status",
			Type:        "elasticsearch",
			Name:        "es_heap",
			Level:       1,
			Title:       "Elasticsearch Cluster Status",
			Description: "cluster status (green/yello/red)",
		},
		&Check{
			Id:          "redis-role",
			Type:        "redis",
			Name:        "redis_role",
			Level:       1,
			Title:       "Redis Role",
			Description: "role of redis server (master/slave)",
		},
	}

	s.Use("alerts")
	for _, check := range data {
		r.Table("checks").Insert(check).RunWrite(s)
	}
	r.Table("checks").IndexCreateFunc("type_name", func(row r.Term) interface{} {
		return []interface{}{row.Field("type"), row.Field("name")}
	}).RunWrite(s)
	return nil
}
开发者ID:adamliesko,项目名称:platform-ws-services,代码行数:39,代码来源:model_check_seed_test.go


示例4: initDb

func initDb() {
	var session *r.Session

	session, err := r.Connect(r.ConnectOpts{
		Address: "localhost:28015",
	})
	if err != nil {
		log.Fatalln(err.Error())
	}

	session.SetMaxOpenConns(5)

	r.TableDrop("cars").Run(session)

	resp, err := r.TableCreate("cars").RunWrite(session)
	if err != nil {
		log.Println(err)
	}

	fmt.Printf("%d table created\n", resp.TablesCreated)

	s = session
}
开发者ID:yelinaung,项目名称:rethink-test,代码行数:23,代码来源:hello.go


示例5: killSession

//killSession disconnects from the database
func killSession(session *r.Session) {
	session.Close()
}
开发者ID:ederoyd46,项目名称:osmimport-go,代码行数:4,代码来源:database.go


示例6: TestTravelPlanning

	"testing"

	"github.com/StephanDollberg/go-json-rest-middleware-jwt"
	"github.com/ant0ine/go-json-rest/rest"
	"github.com/ant0ine/go-json-rest/rest/test"
	r "github.com/dancannon/gorethink"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

const database = "travelPlanningTest"

var (
	Response         *httptest.ResponseRecorder
	Request          *http.Request
	testConn         *r.Session
	tst              *testing.T
	loginCredentials = map[string]string{"username": "admin", "password": "admin"}
)

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)
开发者ID:yetis-br,项目名称:travelPlanning,代码行数:31,代码来源:travelPlanning_suite_test.go


示例7: Compute

func (bmo *BMO) Compute(input *os.File) {

	var err error
	var cur *r.Cursor
	var session *r.Session

	// set up database connection pool
	session, err = r.Connect(r.ConnectOpts{
		Addresses:     bmo.nodes,
		Database:      bmo.database,
		DiscoverHosts: true,
	})
	session.SetMaxOpenConns(POOL_SIZE)
	if err != nil {
		log.Fatalln(err)
	}
	// ensure table is present
	var tableNames []string
	cur, err = r.DB(bmo.database).TableList().Run(session)
	if err != nil {
		log.Fatalln(err)
	}
	cur.All(&tableNames)
	set := make(map[string]bool)
	for _, v := range tableNames {
		set[v] = true
	}
	if !set[bmo.table] {
		log.Println("Creating table ", bmo.table)
		_, err = r.DB(bmo.database).TableCreate(bmo.table).RunWrite(session)
		if err != nil {
			log.Fatalln("Error creating table: ", err)
			os.Exit(1)
		}
	}

	// deliver the messages
	decoder := json.NewDecoder(input)
	ms := make([]Message, INSERT_BATCH_SIZE)
	var m *Message
	var i uint64
	var ignoreLast bool

	pool, _ := tunny.CreatePoolGeneric(POOL_SIZE).Open()
	defer pool.Close()

	table := r.Table(bmo.table)
	insertOptions := r.InsertOpts{Durability: "soft"}

	insert := func() {
		j := i
		if !ignoreLast {
			j += 1
		}
		_, err = table.Insert(ms[:j], insertOptions).RunWrite(session)
		if err != nil {
			log.Fatal(err)
			os.Exit(1)
		}
	}

	for {
		i = bmo.seq % INSERT_BATCH_SIZE
		m = &ms[i]
		err = decoder.Decode(&m)

		switch {
		case err == io.EOF:
			ignoreLast = true
			pool.SendWork(insert)
			return
		case err != nil:
			ignoreLast = true
			pool.SendWork(insert)
			log.Fatal("Can't parse json input, \"", err, "\". Object #", bmo.seq, ", after ", m)
			os.Exit(1)
		default:
			if i+1 == INSERT_BATCH_SIZE {
				ignoreLast = false
				pool.SendWork(insert)
			}
		}

		bmo.seq += 1
	}
}
开发者ID:cosmicturtle,项目名称:bmo,代码行数:86,代码来源:bmo.go



注:本文中的github.com/dancannon/gorethink.Session类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gorethink.Term类代码示例发布时间:2022-05-23
下一篇:
Golang gorethink.Cursor类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap