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

Golang log.Info函数代码示例

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

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



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

示例1: TestHMain

func TestHMain(t *testing.T) {
	reset(t)
	user, fid, fidT := seedDBUser(t)
	req := dt.Request{CMD: "Hi", UserID: user.ID}

	// Test via a UserID
	byt, err := json.Marshal(req)
	if err != nil {
		t.Fatal(err)
	}
	c, b := request("POST", "/", byt)
	if c != http.StatusOK {
		log.Info(b)
		t.Fatal("expected", http.StatusOK, "got", c)
	}
	if b == "Something went wrong with my wiring... I'll get that fixed up soon." {
		t.Fatal(`expected "Hi there :)" but got "Something went wrong..."`)
	}

	// Test via a FlexID
	req.UserID = 0
	req.FlexID = fid
	req.FlexIDType = fidT
	byt, err = json.Marshal(req)
	if err != nil {
		t.Fatal(err)
	}
	c, b = request("POST", "/", byt)
	if c != http.StatusOK {
		log.Info(b)
		t.Fatal("expected", http.StatusOK, "got", c)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:33,代码来源:handlers_test.go


示例2: cleanup

func cleanup() {
	q := `DELETE FROM messages`
	_, err := p.DB.Exec(q)
	if err != nil {
		log.Info("failed to delete messages.", err)
	}
	q = `DELETE FROM states`
	_, err = p.DB.Exec(q)
	if err != nil {
		log.Info("failed to delete messages.", err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:12,代码来源:iterate_test.go


示例3: writeError

func writeError(w http.ResponseWriter, err error) {
	tmp := strings.Replace(err.Error(), `"`, "'", -1)
	errS := struct{ Msg string }{Msg: tmp}
	byt, err := json.Marshal(errS)
	if err != nil {
		log.Info("failed to marshal error", err)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	if _, err = w.Write(byt); err != nil {
		log.Info("failed to write error", err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:13,代码来源:handlers.go


示例4: TestPluginSearch

func TestPluginSearch(t *testing.T) {
	query := "weather"
	var byt []byte
	var err error
	if testing.Short() {
		log.Info("stubbing plugin search results in short mode.")
		byt = []byte(`[{"Name":"Weather","Valid":true}]`)
	} else {
		byt, err = searchItsAbot(query)
		if err != nil {
			t.Fatal(err)
		}
	}
	var b []byte
	buf := bytes.NewBuffer(b)
	if err = outputPluginResults(buf, byt); err != nil {
		t.Fatal(err)
	}
	tmp := buf.String()
	if !strings.Contains(tmp, "NAME") {
		t.Fatal(err)
	}
	if !strings.Contains(tmp, "Weather") {
		t.Fatal(err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:26,代码来源:abot_test.go


示例5: fetchTrainingSentences

// fetchTrainingSentences retrieves training sentences from a remote source
// (via ITSABOT_URL, which defaults to itsabot.org).
func fetchTrainingSentences(pluginID uint64, name string) ([]tSentence, error) {
	c := &http.Client{Timeout: 10 * time.Second}
	pid := strconv.FormatUint(pluginID, 10)
	u := os.Getenv("ITSABOT_URL") + "/api/plugins/train/" + pid
	req, err := http.NewRequest("GET", u, nil)
	if err != nil {
		return nil, err
	}
	resp, err := c.Do(req)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err = resp.Body.Close(); err != nil {
			log.Info("failed to close response body.", err)
		}
	}()
	ss := []tSentence{}

	// This occurs when the plugin has not been published, which we should
	// ignore on boot.
	if resp.StatusCode == http.StatusBadRequest {
		log.Infof("warn: plugin %s has not been published", name)
		return ss, nil
	}
	err = json.NewDecoder(resp.Body).Decode(&ss)
	return ss, err
}
开发者ID:itsabot,项目名称:abot,代码行数:30,代码来源:boot.go


示例6: hapiAdmins

// hapiAdmins returns a list of all admins with the training and manage team
// permissions.
func hapiAdmins(w http.ResponseWriter, r *http.Request) {
	if os.Getenv("ABOT_ENV") != "test" {
		if !isAdmin(w, r) {
			return
		}
		if !isLoggedIn(w, r) {
			return
		}
	}
	var admins []struct {
		ID    uint64
		Name  string
		Email string
	}
	q := `SELECT id, name, email FROM users WHERE admin=TRUE`
	err := db.Select(&admins, q)
	if err != nil && err != sql.ErrNoRows {
		writeErrorInternal(w, err)
		return
	}
	b, err := json.Marshal(admins)
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	_, err = w.Write(b)
	if err != nil {
		log.Info("failed to write response.", err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:32,代码来源:handlers.go


示例7: hapiRemoteTokens

// hapiRemoteTokens returns the final six bytes of each auth token used to
// authenticate to the remote service and when.
func hapiRemoteTokens(w http.ResponseWriter, r *http.Request) {
	if os.Getenv("ABOT_ENV") != "test" {
		if !isAdmin(w, r) {
			return
		}
		if !isLoggedIn(w, r) {
			return
		}
	}

	// We initialize the variable here because we want empty slices to
	// marshal to [], not null
	auths := []struct {
		Token     string
		Email     string
		CreatedAt time.Time
		PluginIDs dt.Uint64Slice
	}{}
	q := `SELECT token, email, pluginids, createdat FROM remotetokens`
	err := db.Select(&auths, q)
	if err != nil && err != sql.ErrNoRows {
		writeErrorInternal(w, err)
		return
	}
	byt, err := json.Marshal(auths)
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	_, err = w.Write(byt)
	if err != nil {
		log.Info("failed to write response.", err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:36,代码来源:handlers.go


示例8: TestHIndex

func TestHIndex(t *testing.T) {
	c, b := request("GET", "/", nil)
	if c != http.StatusOK {
		log.Info(b)
		t.Fatal("expected", http.StatusOK, "got", c)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:7,代码来源:handlers_test.go


示例9: loadLocation

func loadLocation(l string) *time.Location {
	loc, err := time.LoadLocation(l)
	if err != nil {
		log.Info("failed to load location.", l)
	}
	return loc
}
开发者ID:itsabot,项目名称:abot,代码行数:7,代码来源:timeparse.go


示例10: generatePlugin

func generatePlugin(l *log.Logger, name string) error {
	// Log in to get the maintainer email
	if os.Getenv("ABOT_ENV") != "test" {
		p := filepath.Join(os.Getenv("HOME"), ".abot.conf")
		if _, err := os.Stat(p); os.IsNotExist(err) {
			login()
		}
	}

	// Ensure the name and path are unique globally
	var words []string
	var lastIdx int
	name = strings.Replace(name, " ", "_", -1)
	dirName := name
	for i, letter := range name {
		if i == 0 {
			continue
		}
		if unicode.IsUpper(letter) {
			words = append(words, name[lastIdx:i])
			lastIdx = i
		}
	}
	words = append(words, name[lastIdx:])
	dirName = strings.Join(words, "_")
	dirName = strings.ToLower(dirName)
	name = strings.ToLower(name)

	// Create the directory
	if err := os.Mkdir(dirName, 0744); err != nil {
		return err
	}

	// Generate a plugin.json file
	if err := buildPluginJSON(dirName, name); err != nil {
		log.Info("failed to create plugin.json")
		return err
	}

	// Generate name.go and name_test.go files with starter keywords and
	// state machines
	if err := buildPluginScaffoldFile(dirName, name); err != nil {
		log.Info("failed to create plugin scaffold file")
		return err
	}
	return nil
}
开发者ID:itsabot,项目名称:abot,代码行数:47,代码来源:abot.go


示例11: ExtractCities

// ExtractCities efficiently from a user's message.
func ExtractCities(db *sqlx.DB, in *dt.Msg) ([]dt.City, error) {
	// Interface type is used to expand the args in db.Select below.
	// Although we're only storing strings, []string{} doesn't work.
	var args []interface{}

	// Look for "at", "in", "on" prepositions to signal that locations
	// follow, skipping everything before
	var start int
	for i := range in.Stems {
		switch in.Stems[i] {
		case "at", "in", "on":
			start = i
			break
		}
	}

	// Prepare sentence for iteration
	tmp := regexNonWords.ReplaceAllString(in.Sentence, "")
	words := strings.Fields(strings.Title(tmp))

	// Iterate through words and bigrams to assemble a DB query
	for i := start; i < len(words); i++ {
		args = append(args, words[i])
	}
	bgs := bigrams(words, start)
	for i := 0; i < len(bgs); i++ {
		args = append(args, bgs[i])
	}

	cities := []dt.City{}
	q := `SELECT name, countrycode FROM cities
	      WHERE countrycode='US' AND name IN (?)
	      ORDER BY LENGTH(name) DESC`
	query, arguments, err := sqlx.In(q, args)
	query = db.Rebind(query)
	rows, err := db.Query(query, arguments...)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err = rows.Close(); err != nil {
			log.Info("failed to close db rows.", err)
		}
	}()
	for rows.Next() {
		city := dt.City{}
		if err = rows.Scan(&city.Name, &city.CountryCode); err != nil {
			return nil, err
		}
		cities = append(cities, city)
	}
	if err = rows.Err(); err != nil {
		return nil, err
	}
	if len(cities) == 0 {
		return nil, ErrNotFound
	}
	return cities, nil
}
开发者ID:itsabot,项目名称:abot,代码行数:60,代码来源:extract.go


示例12: hapiAdminsUpdate

// hapiAdminsUpdate adds or removes admin permission from a given user.
func hapiAdminsUpdate(w http.ResponseWriter, r *http.Request) {
	if os.Getenv("ABOT_ENV") != "test" {
		if !isAdmin(w, r) {
			return
		}
		if !isLoggedIn(w, r) {
			return
		}
		if !isValidCSRF(w, r) {
			return
		}
	}
	var req struct {
		ID    uint64
		Email string
		Admin bool
	}
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		writeErrorBadRequest(w, err)
		return
	}
	// This is a clever way to update the user using EITHER email or ID
	// (whatever the client had available). Then we return the ID of the
	// updated entry to send back to the client for faster future requests.
	if req.ID > 0 && len(req.Email) > 0 {
		writeErrorBadRequest(w, errors.New("only one value allowed: ID or Email"))
		return
	}
	q := `UPDATE users SET admin=$1 WHERE id=$2 OR email=$3 RETURNING id`
	err := db.QueryRow(q, req.Admin, req.ID, req.Email).Scan(&req.ID)
	if err == sql.ErrNoRows {
		// This error is frequently user-facing.
		writeErrorBadRequest(w, errors.New("User not found."))
		return
	}
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	var user struct {
		ID    uint64
		Email string
		Name  string
	}
	q = `SELECT id, email, name FROM users WHERE id=$1`
	if err = db.Get(&user, q, req.ID); err != nil {
		writeErrorInternal(w, err)
		return
	}
	byt, err := json.Marshal(user)
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	_, err = w.Write(byt)
	if err != nil {
		log.Info("failed to write response.", err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:60,代码来源:handlers.go


示例13: TestMain

func TestMain(m *testing.M) {
	if err := core.LoadEnvVars(); err != nil {
		log.Info("failed to load env vars", err)
	}
	if err := os.Setenv("ABOT_ENV", "test"); err != nil {
		log.Fatal(err)
	}
	os.Exit(m.Run())
}
开发者ID:itsabot,项目名称:abot,代码行数:9,代码来源:abot_test.go


示例14: TestPluginGenerate

func TestPluginGenerate(t *testing.T) {
	defer func() {
		if err := os.RemoveAll("__test"); err != nil {
			log.Info("failed to clean up __test dir.", err)
		}
		if err := os.RemoveAll("test_here"); err != nil {
			log.Info("failed to clean up __test dir.", err)
		}
	}()

	// generate plugin
	l := log.New("")
	l.SetFlags(0)
	if err := generatePlugin(l, "__test"); err != nil {
		t.Fatal(err)
	}
	if err := generatePlugin(l, "TestHere"); err != nil {
		t.Fatal(err)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:20,代码来源:abot_test.go


示例15: sendEventsTick

func sendEventsTick(evtChan chan *dt.ScheduledEvent, t time.Time) {
	// Listen for events that need to be sent.
	go func(chan *dt.ScheduledEvent) {
		q := `UPDATE scheduledevents SET sent=TRUE WHERE id=$1`
		select {
		case evt := <-evtChan:
			log.Debug("received event")
			if smsConn == nil {
				log.Info("failed to send scheduled event (missing SMS driver). will retry.")
				return
			}
			// Send event. On error, event will be retried next
			// minute.
			if err := evt.Send(smsConn); err != nil {
				log.Info("failed to send scheduled event", err)
				return
			}
			// Update event as sent
			if _, err := db.Exec(q, evt.ID); err != nil {
				log.Info("failed to update scheduled event as sent",
					err)
				return
			}
		}
	}(evtChan)

	q := `SELECT id, content, flexid, flexidtype
		      FROM scheduledevents
		      WHERE sent=false AND sendat<=$1`
	evts := []*dt.ScheduledEvent{}
	if err := db.Select(&evts, q, time.Now()); err != nil {
		log.Info("failed to queue scheduled event", err)
		return
	}
	for _, evt := range evts {
		// Queue the event for sending
		evtChan <- evt
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:39,代码来源:scheduled_event.go


示例16: TestMain

func TestMain(m *testing.M) {
	if err := LoadEnvVars(); err != nil {
		log.Info("failed to load env vars", err)
	}
	if err := os.Setenv("ABOT_ENV", "test"); err != nil {
		log.Fatal("failed to set ABOT_ENV", err)
	}
	var err error
	router, err = NewServer()
	if err != nil {
		log.Fatal("failed to start server", err)
	}
	os.Exit(m.Run())
}
开发者ID:itsabot,项目名称:abot,代码行数:14,代码来源:handlers_test.go


示例17: testPlugin

func testPlugin() (int, error) {
	if err := core.LoadPluginsGo(); err != nil {
		return 0, err
	}
	r := plugin.TestPrepare()
	plugin.TestCleanup()
	var count int
	for _, plg := range core.PluginsGo {
		log.Info("loading", plg.Name)
		for _, test := range plg.Tests {
			log.Info("running", test)
			count++
			for in, exps := range test {
				err := plugin.TestReq(r, in, exps)
				if err != nil {
					return count, err
				}
			}
		}
	}
	plugin.TestCleanup()
	return count, nil
}
开发者ID:itsabot,项目名称:abot,代码行数:23,代码来源:abot.go


示例18: TestHAPIProfile

func TestHAPIProfile(t *testing.T) {
	reset(t)
	user, _, _ := seedDBUser(t)
	seedDBUserSession(t, user)

	c, b := userRequest("GET", "/api/user/profile.json", nil, user)
	if c != http.StatusOK {
		log.Info(b)
		t.Fatal("expected", http.StatusOK, "got", c)
	}
	if !strings.Contains(b, "Name") {
		t.Fatal(`expected "Name" but got`, b)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:14,代码来源:handlers_test.go


示例19: TestHSignupSubmit

func TestHSignupSubmit(t *testing.T) {
	reset(t)
	u := "http://localhost:" + os.Getenv("PORT") + "/api/signup.json"
	data := []byte(`{
		"Name": "Tester",
		"Email": "[email protected]",
		"Password": "password",
		"FID": "+13105555555"
	}`)
	c, b := request("POST", u, data)
	if c != http.StatusOK {
		log.Info(b)
		t.Fatal("expected", http.StatusOK, "got", c)
	}
}
开发者ID:itsabot,项目名称:abot,代码行数:15,代码来源:handlers_test.go


示例20: preprocess

// preprocess converts a user input into a Msg that's been persisted to the
// database
func preprocess(r *http.Request) (*dt.Msg, error) {
	req := &dt.Request{}
	err := json.NewDecoder(r.Body).Decode(req)
	if err != nil {
		log.Info("could not parse empty body", err)
		return nil, err
	}
	sendPostReceiveEvent(&req.CMD)
	u, err := dt.GetUser(db, req)
	if err != nil {
		return nil, err
	}
	sendPreProcessingEvent(&req.CMD, u)
	// TODO trigger training if needed (see buildInput)
	return NewMsg(u, req.CMD)
}
开发者ID:itsabot,项目名称:abot,代码行数:18,代码来源:process.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang db.GetCollection函数代码示例发布时间:2022-05-23
下一篇:
Golang log.Debug函数代码示例发布时间: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