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

Golang wcg.NewLogger函数代码示例

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

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



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

示例1: main

func main() {
	app := cli.NewApp()
	app.Name = "speedland-agent"
	app.Usage = "A agent command for speedland.net"
	app.Version = "1.0.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			"config, c",
			"wcg.ini",
			"configuration file",
			"WCG_INI_FILE",
		},
	}
	app.Before = func(c *cli.Context) error {
		wcg.ConfigureProcess(c.String("config"))
		// normalize path
		lib.Config.Endpoint.Path = ""
		wcg.NewLogger(nil).Info("Used configurn file: %q", c.String("config"))
		wcg.NewLogger(nil).Info("Target Endpoint: %q", lib.Config.Endpoint)
		wcg.NewLogger(nil).Debug("Token: %q", lib.Config.Token)
		return nil
	}
	app.Commands = commands.AllCommands()
	app.Run(os.Args)
	wcg.WaitLogs()
}
开发者ID:speedland,项目名称:apps,代码行数:26,代码来源:main.go


示例2: TestDelChannelApi

func TestDelChannelApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		// prepare
		d := NewTvChannelDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))
		ent1 := &tv.TvChannel{"c1", "s1", "foo", "bar"}
		ent2 := &tv.TvChannel{"c2", "s2", "hoge", "piyo"}
		d.Put(d.NewKey(ent1.Key(), 0, nil), ent1)
		d.Put(d.NewKey(ent2.Key(), 0, nil), ent2)

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 2
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm TvChannel entities has been stored within a timeout window.")
		p := app.Api.Path("/channels/c1/s1.json")
		req := ts.Delete(p)
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)

		err = util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "DELETE %s Confirm TvChannel entities has been deleted via API within a timeout window.", p)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(!mc.Exists(MC_KEY_CHANNELS), "DELETE %s should invalidate the cache", p)

	})
}
开发者ID:speedland,项目名称:apps,代码行数:33,代码来源:api_channels_test.go


示例3: TestAddKeywordApi

func TestAddKeywordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		p := app.Api.Path("/keywords/")
		req := ts.PostForm(p, url.Values{
			"keyword":  []string{"モーニング娘。'15"},
			"category": []string{"モーニング娘。"},
			"scope":    []string{"1"},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		var got map[string]interface{}
		res := req.RouteTo(app.Routes())
		res.Json(&got)
		assert.HttpStatus(201, res)
		assert.EqStr(
			"http://localhost:8080/api/pt/keywords/モーニング娘。'15.json",
			got["location"].(string),
			"POST %s location",
			p,
		)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(!mc.Exists(MC_KEY_KEYWORDS), "POST %s should invalidate the cache", p)

	})
}
开发者ID:speedland,项目名称:apps,代码行数:27,代码来源:api_keywords_test.go


示例4: TestChannel_AddAndDelCrawlerConfig

func TestChannel_AddAndDelCrawlerConfig(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := wcg.NewAssert(t)

		// prepare
		d := NewCrawlerConfigDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))
		d.Add(&tv.CrawlerConfig{
			Keyword:  "キーワード1",
			Category: "カテゴリー1",
			Scope:    1,
		})
		d.Add(&tv.CrawlerConfig{
			Keyword:  "キーワード2",
			Category: "カテゴリー2",
			Scope:    1,
		})

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 2
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm CrawlerConfig entities has been stored within a timeout window.")

		d.Delete("キーワード1")
		err = util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm CrawlerConfig entities has been deleted within a timeout window.")

		err = d.Delete("Not Exists")
		assert.Nil(err, "Delete should not return even trying to delete the unexising keyword.")
	})
}
开发者ID:speedland,项目名称:apps,代码行数:34,代码来源:crawler_config_driver_test.go


示例5: TestAddChannelApi

func TestAddChannelApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		p := app.Api.Path("/channels/")
		req := ts.PostForm(p, url.Values{
			"cid":             []string{"c1"},
			"sid":             []string{"s1"},
			"name":            []string{"foo"},
			"iepg_station_id": []string{"bar"},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		var got map[string]interface{}
		res := req.RouteTo(app.Routes())
		res.Json(&got)
		assert.HttpStatus(201, res)
		assert.EqStr(
			"http://localhost:8080/api/pt/channels/c1/s1.json",
			got["location"].(string),
			"POST %s location",
			p,
		)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(!mc.Exists(MC_KEY_CHANNELS), "POST %s should invalidate the cache", p)

	})
}
开发者ID:speedland,项目名称:apps,代码行数:28,代码来源:api_channels_test.go


示例6: NewAppContextFromTestServer

func NewAppContextFromTestServer(app *lib.App, ts *test.TestServer) *lib.AppContext {
	return &lib.AppContext{
		app,
		ts.Context,
		wcg.NewLogger(nil),
	}
}
开发者ID:speedland,项目名称:apps,代码行数:7,代码来源:context.go


示例7: TestGetOverlaps

func TestGetOverlaps(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		var found []*tv.TvRecord
		const timeForm = "2006/01/02 15:04:05"
		assert := wcg.NewAssert(t)
		d := NewTvRecordDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		base := genTestRecord()
		base.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:00:00")
		base.EndAt, _ = time.Parse(timeForm, "2014/01/01 13:00:00")
		d.Save(base)
		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm TvRecord entities has been stored within a timeout window.")

		// case1: no overlaps
		r := genTestRecord()
		r.StartAt, _ = time.Parse(timeForm, "2014/01/01 10:50:00")
		r.EndAt, _ = time.Parse(timeForm, "2014/01/01 11:10:00")
		found, err = d.GetOverlaps(r)
		assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case1)")
		assert.EqInt(0, len(found), "TvRecordDriver#GetOverlaps should return empty array (case1)")

		// case 2: base.end < r.start
		r = genTestRecord()
		r.StartAt, _ = time.Parse(timeForm, "2014/01/01 13:50:00")
		r.EndAt, _ = time.Parse(timeForm, "2014/01/01 14:10:00")
		found, err = d.GetOverlaps(r)
		assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case2)")
		assert.EqInt(0, len(found), "TvRecordDriver#GetOverlaps should return empty array (case2)")

		// case 3: base.start < r.start < base.end
		r = genTestRecord()
		r.StartAt, _ = time.Parse(timeForm, "2014/01/01 11:50:00")
		r.EndAt, _ = time.Parse(timeForm, "2014/01/01 12:10:00")
		found, err = d.GetOverlaps(r)
		assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case3)")
		assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case3)")

		// case 4: r.start < base.end < r.end
		r = genTestRecord()
		r.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:50:00")
		r.EndAt, _ = time.Parse(timeForm, "2014/01/01 13:10:00")
		found, err = d.GetOverlaps(r)
		assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case4)")
		assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case4)")

		// case 5: r.start < base.start < base.end < r.end
		r = genTestRecord()
		r.StartAt, _ = time.Parse(timeForm, "2014/01/01 12:10:00")
		r.EndAt, _ = time.Parse(timeForm, "2014/01/01 12:50:00")
		found, err = d.GetOverlaps(r)
		assert.Nil(err, "TvRecordDriver#GetOverlaps should not return an error (case4)")
		assert.EqInt(1, len(found), "TvRecordDriver#GetOverlaps should return an array with an entity (case4)")
	})
}
开发者ID:speedland,项目名称:apps,代码行数:58,代码来源:record_driver_test.go


示例8: FixtureFromMap

func FixtureFromMap(ctx appengine.Context, arr []map[string]interface{}) error {
	logger := wcg.NewLogger(nil)
	for _, v := range arr {
		if err := loadJsonToDatastore(ctx, nil, v, logger); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:speedland,项目名称:wcg,代码行数:9,代码来源:fixture.go


示例9: Run

func Run() {
	go ping.Run()
	go recorder.Run()
	go statsd.Run()

	// block the main until receiving the signal
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
	s := <-c
	wcg.NewLogger(nil).Info("Exitting the signal with %s", s)
	// TODO: delegate the notification to each job
}
开发者ID:speedland,项目名称:agent,代码行数:12,代码来源:run.go


示例10: TestDeleteRecordApi

func TestDeleteRecordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		d := NewRecordCacheDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		// create an empty cache
		var got []tv.TvRecord
		p := app.Api.Path("/records/")
		req := ts.Get(p)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		res.Json(&got)
		assert.EqInt(0, len(got), "GET %s should return 2 TvRecord entities.")
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "GET %s should create RecordCacheTypeTvRecord cache", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should create RecordCacheTypeIEpg cache", p)

		// prepare
		in_window := genTestRecord()
		in_window.StartAt = d.today.Add(1 * time.Hour)
		in_window.EndAt = d.today.Add(2 * time.Hour)
		d.TvRecord.Save(in_window)

		future := genTestRecord()
		future.StartAt = d.today.Add(RECORD_TIME_WINDOW + 1*time.Hour)
		future.EndAt = future.StartAt.Add(1 * time.Hour)
		d.TvRecord.Save(future)

		err := util.WaitFor(func() bool {
			records, _ := d.TvRecord.NewQuery().Count()
			return records == 2
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm TvRecord entities has been stored within a timeout window.")

		// case 1: future
		p = fmt.Sprintf("%s%s.json", app.Api.Path("/records/"), future.Key())
		req = ts.Delete(p)
		lib.SetApiTokenForTest(req, lib.Admin)
		res = req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "POST %s should not invalidate RecordCacheTypeTvRecord cache (future record)", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should not invalidate RecordCacheTypeIEpg cache (future record)", p)

		// case 2: in recording window
		p = fmt.Sprintf("%s%s.json", app.Api.Path("/records/"), in_window.Key())
		req = ts.Delete(p)
		lib.SetApiTokenForTest(req, lib.Admin)
		res = req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "POST %s should invalidate RecordCacheTypeTvRecord cache (in_window record)", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should not invalidate RecordCacheTypeIEpg cache (in_window record)", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:52,代码来源:api_record_test.go


示例11: TestDelKeywordApi

func TestDelKeywordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		// prepare
		d := NewCrawlerConfigDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))
		d.Add(&tv.CrawlerConfig{
			Keyword:  "モーニング娘。'15",
			Category: "モーニング娘",
			Scope:    tv.FEED_SCOPE_ALL,
		})
		d.Add(&tv.CrawlerConfig{
			Keyword:  "SPEED",
			Category: "SPEED",
			Scope:    tv.FEED_SCOPE_ALL,
		})

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 2
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm CrawlerConfig entities has been stored within a timeout window.")

		p := app.Api.Path("/keywords/モーニング娘。'15.json")
		req := ts.Delete(p)
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)

		err = util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "DELETE %s Confirm CrawlerConfig entities has been deleted via API within a timeout window.", p)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(!mc.Exists(MC_KEY_KEYWORDS), "DELETE %s should invalidate the cache", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:39,代码来源:api_keywords_test.go


示例12: TestRecordCache_GetRecords_and_Invalidate

func TestRecordCache_GetRecords_and_Invalidate(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := wcg.NewAssert(t)
		d := NewRecordCacheDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		// prepare
		in_window := genTestRecord()
		in_window.StartAt = d.today.Add(1 * time.Hour)
		in_window.EndAt = d.today.Add(2 * time.Hour)
		d.TvRecord.Save(in_window)

		future := genTestRecord()
		future.StartAt = d.today.Add(RECORD_TIME_WINDOW + 1*time.Hour)
		future.EndAt = future.StartAt.Add(1 * time.Hour)
		d.TvRecord.Save(future)

		past := genTestRecord()
		past.StartAt = d.today.Add(-RECORD_TIME_WINDOW - 1*time.Hour)
		past.EndAt = past.StartAt.Add(30 * time.Minute)
		d.TvRecord.Save(past)

		in_window_iepg := genTestIEpg()
		in_window.StartAt = d.today.Add(4 * time.Hour)
		in_window.EndAt = d.today.Add(5 * time.Hour)
		d.IEpg.Save(in_window_iepg)

		err := util.WaitFor(func() bool {
			records, _ := d.TvRecord.NewQuery().Count()
			iepgs, _ := d.IEpg.NewQuery().Count()
			return records+iepgs == 4
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm TvRecord/IEpg entities has been stored within a timeout window.")

		list, err := d.GetRecords(false)
		assert.Nil(err, "RecordCache#GetRecords should not return an error")
		assert.EqInt(2, len(list), "RecordCache#GetRecords should return 2 records in a time window")

		// cache check
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "RecordCache#GetRecords should create RecordCacheTypeTvRecord on memcache.")
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "RecordCache#GetRecords should create RecordCacheTypeIEpg on memcache.")

		// invalidate the keys
		assert.Ok(!d.Invalidate(future), "RecordCache#Invalidate should not return true if the passed record is out of window (future)")
		assert.Ok(!d.Invalidate(past), "RecordCache#Invalidate should not return true if the passed record is out of window (future)")
		assert.Ok(d.Invalidate(in_window), "RecordCache#Invalidate should return true if the passed record is in window")
		assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "RecordCache#GetRecords should invalidate RecordCacheTypeTvRecord on memcache.")

		assert.Ok(d.Invalidate(in_window_iepg), "RecordCache#Invalidate should return true if the passed record is in window (iepg)")
		assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "RecordCache#GetRecords should invalidate RecordCacheTypeIEpg on memcache.")
	})
}
开发者ID:speedland,项目名称:apps,代码行数:51,代码来源:record_cache_driver_test.go


示例13: TestListKeywordApi

func TestListKeywordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)

		// prepare
		d := NewCrawlerConfigDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))
		d.Add(&tv.CrawlerConfig{
			Keyword:  "キーワード1",
			Category: "カテゴリー1",
			Scope:    1,
		})
		d.Add(&tv.CrawlerConfig{
			Keyword:  "キーワード2",
			Category: "カテゴリー2",
			Scope:    1,
		})

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 2
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm CrawlerConfig entities has been stored within a timeout window.")

		var got []*tv.CrawlerConfig
		p := app.Api.Path("/keywords/") + "?force=true"
		req := ts.Get(p)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		res.Json(&got)
		assert.EqStr("キーワード2", got[0].Keyword, "GET %s should return the list ordered by creation time.", p)
		assert.EqStr("キーワード1", got[1].Keyword, "GET %s should return the list ordered by creation time.", p)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(mc.Exists(MC_KEY_KEYWORDS), "GET %s should create the cache", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:37,代码来源:api_keywords_test.go


示例14: TestCreateRecordApi

func TestCreateRecordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		d := NewRecordCacheDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		// create an empty cache
		var got []tv.TvRecord
		p := app.Api.Path("/records/")
		req := ts.Get(p)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		res.Json(&got)
		assert.EqInt(0, len(got), "GET %s should return 2 TvRecord entities.")
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "GET %s should create RecordCacheTypeTvRecord cache", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should create RecordCacheTypeIEpg cache", p)

		now := time.Now()

		// case 1: future
		req = ts.PostForm(p, url.Values{
			"title":    []string{"Title"},
			"category": []string{"Category"},
			"cid":      []string{"27"},
			"sid":      []string{"hd"},
			"start_at": []string{util.FormatDateTime(now.Add(RECORD_TIME_WINDOW + 24*time.Hour))},
			"end_at":   []string{util.FormatDateTime(now.Add(RECORD_TIME_WINDOW + 25*time.Hour))},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		res = req.RouteTo(app.Routes())
		assert.HttpStatus(201, res)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "POST %s should not invalidate RecordCacheTypeTvRecord cache (future record)", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should not invalidate RecordCacheTypeIEpg cache (future record)", p)

		// case 2: in recording window
		req = ts.PostForm(p, url.Values{
			"title":    []string{"Title"},
			"category": []string{"Category"},
			"cid":      []string{"27"},
			"sid":      []string{"hd"},
			"start_at": []string{util.FormatDateTime(now)},
			"end_at":   []string{util.FormatDateTime(now.Add(1 * time.Hour))},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		res = req.RouteTo(app.Routes())
		assert.HttpStatus(201, res)
		assert.Ok(!d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "POST %s should invalidate RecordCacheTypeTvRecord cache (in window)", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should not invalidate RecordCacheTypeIEpg cache (in window)", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:49,代码来源:api_record_test.go


示例15: DatastoreFixture

func DatastoreFixture(ctx appengine.Context, path string, bindings interface{}) error {
	logger := wcg.NewLogger(nil)
	logger.Debug("[Fixture] load from %s", path)
	data, err := loadFile(path, bindings)
	if err != nil {
		return err
	}
	var arr []map[string]interface{}
	if err = json.Unmarshal(data, &arr); err != nil {
		return fmt.Errorf("Could not load the json file from %q - JSON Parse error: %v", path, err)
	}
	for _, v := range arr {
		if err := loadJsonToDatastore(ctx, nil, v, logger); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:speedland,项目名称:wcg,代码行数:18,代码来源:fixture.go


示例16: Run

func (*TweetStream) Run() {
	logger := wcg.NewLogger(nil)
	if tweetStreamConfig.ConsumerKey == "" {
		logger.Error("[TweetStream] consumer_key is missing or empty.")
		return
	}
	if tweetStreamConfig.ConsumerSecret == "" {
		logger.Error("[TweetStream] consumer_secret is missing or empty.")
		return
	}
	if tweetStreamConfig.Token == "" {
		logger.Error("[TweetStream] oauth_token is missing or empty.")
		return
	}
	if tweetStreamConfig.TokenSecret == "" {
		logger.Error("[TweetStream] oauth_token_secret is missing or empty.")
		return
	}

	for {
		consumerKey := tweetStreamConfig.ConsumerKey
		consumerSecret := tweetStreamConfig.ConsumerSecret
		client := twitter.NewTwitterClient(consumerKey, consumerSecret, nil)
		client.Token = &twitter.OAuthToken{
			ConsumerKey:    consumerKey,
			ConsumerSecret: consumerSecret,
			Token:          tweetStreamConfig.Token,
			TokenSecret:    tweetStreamConfig.TokenSecret,
		}
		ts, err := client.Stream(&twitter.StreamingParams{
			Track: "#morningmusume15",
		})
		if err != nil {
			logger.Error("[TweetStream] Error building streaming connection: %v", err)
		} else {
			logger.Info("[TweetStream] Connected to the streaming server.")
			ch := ts.GetStreamChannel()
			for tweet := range ch {
				logger.Debug("[TweetStream] %v", tweet)
			}
			logger.Info("[TweetStream] Disconnected from server.")
		}
	}
}
开发者ID:speedland,项目名称:apps,代码行数:44,代码来源:tweetstream.go


示例17: TestListRecordApi

func TestListRecordApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		d := NewRecordCacheDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		// prepare
		in_window := genTestRecord()
		in_window.StartAt = d.today.Add(1 * time.Hour)
		in_window.EndAt = d.today.Add(2 * time.Hour)
		d.TvRecord.Save(in_window)

		future := genTestRecord()
		future.StartAt = d.today.Add(RECORD_TIME_WINDOW + 1*time.Hour)
		future.EndAt = future.StartAt.Add(1 * time.Hour)
		d.TvRecord.Save(future)

		past := genTestRecord()
		past.StartAt = d.today.Add(-RECORD_TIME_WINDOW - 1*time.Hour)
		past.EndAt = past.StartAt.Add(30 * time.Minute)
		d.TvRecord.Save(past)

		in_window_iepg := genTestIEpg()
		in_window.StartAt = d.today.Add(4 * time.Hour)
		in_window.EndAt = d.today.Add(5 * time.Hour)
		d.IEpg.Save(in_window_iepg)

		err := util.WaitFor(func() bool {
			records, _ := d.TvRecord.NewQuery().Count()
			iepgs, _ := d.IEpg.NewQuery().Count()
			return records+iepgs == 4
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm TvRecord/IEpg entities has been stored within a timeout window.")

		var got []tv.TvRecord
		p := app.Api.Path("/records/")
		req := ts.Get(p)
		res := req.RouteTo(app.Routes())
		assert.HttpStatus(200, res)
		res.Json(&got)
		assert.EqInt(2, len(got), "GET %s should return 2 TvRecord entities.", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeTvRecord)), "GET %s should create RecordCacheTypeTvRecord cache", p)
		assert.Ok(d.Cache.Exists(d.GetMcKey(RecordCacheTypeIEpg)), "GET %s should create RecordCacheTypeIEpg cache", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:44,代码来源:api_record_test.go


示例18: Run

func (*Ping) Run() {
	logger := wcg.NewLogger(nil)
	down := 0
	for {
		_, err := api.Ping()
		if err != nil {
			logger.Error("Ping error: %v", err)
			down = down + 1
		} else {
			if down > 0 {
				down = 0
				logger.Info("Ping recovered.")
			} else {
				logger.Debug("Successfully pinged to the endpoint")
			}
		}
		time.Sleep(PingConfig.Interval)
	}
}
开发者ID:speedland,项目名称:agent,代码行数:19,代码来源:ping.go


示例19: TestTvRecord_SyncSave_and_SyncDelete

func TestTvRecord_SyncSave_and_SyncDelete(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := wcg.NewAssert(t)
		d := NewTvRecordDriver(TEST_APP_KEY, ts.Context, wcg.NewLogger(nil))

		r := genTestRecord()
		err := d.SyncSave(r)
		assert.Nil(err, "TvRecordDriver#SyncSave should not return an error")

		c, _ := d.NewQuery().Count()
		assert.EqInt(1, c, "Confirm TvRecord entities has been stored.")

		err = d.SyncDelete(r.Key())
		assert.Nil(err, "TvRecordDriver#SyncDelete should not return an error")

		c, _ = d.NewQuery().Count()
		assert.EqInt(0, c, "Confirm TvRecord entities has been deleted.")
	})
}
开发者ID:speedland,项目名称:apps,代码行数:19,代码来源:record_driver_test.go


示例20: TestListChannelApi

func TestListChannelApi(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		p := app.Api.Path("/channels/")
		err := util.WaitFor(func() bool {
			var got []tv.TvChannel
			req := ts.Get(p)
			res := req.RouteTo(app.Routes())
			assert.HttpStatus(200, res)
			res.Json(&got)
			return len(got) > 0
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "GET %s should return the list of TvChannels within a timeout window.", p)

		// Confirm cache invalidation
		mc := memcache.NewDriver(ts.Context, wcg.NewLogger(nil))
		assert.Ok(mc.Exists(MC_KEY_CHANNELS), "GET %s should create the cache", p)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:19,代码来源:api_channels_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang wcg.Request类代码示例发布时间:2022-05-28
下一篇:
Golang wcg.NewAssert函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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