本文整理汇总了Golang中github.com/astaxie/beego.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StartWebsockets
// StartConnector starts up the websocket connector of the bee server
// config settings from config file
// commandChan channel to send commands to the controller
// doneChan channel to signal end or get it signaled
func StartWebsockets(doneChan chan bool) {
address := beego.AppConfig.String("httpaddr")
dir := beego.AppConfig.String("websockets::dir")
port := beego.AppConfig.String("websockets::port")
beego.Trace("dir:", dir, "address:", address, "port:", port)
http.Handle(dir, websocket.Handler(func(ws *websocket.Conn) {
beego.Trace("New socket connection started ...")
s := socket{ws, make(chan bool)}
go translateMessages(s)
encoder := json.NewEncoder(s)
data := Data{
"Time": time.Now().UnixNano() / int64(time.Millisecond),
}
encoder.Encode(&data)
<-s.done
beego.Trace("Socket connection gone ...")
}))
beego.Trace("--- Spielplatz connector started on ", address+":"+port, ". Listening ...")
err := http.ListenAndServe(address+":"+port, nil)
if err != nil {
beego.Error(err)
doneChan <- true
}
}
示例2: init
func init() {
// Initialized recent viewed project list.
num, err := beego.AppConfig.Int("recentViewedProNum")
if err == nil {
recentViewedProNum = num
beego.Trace("Loaded 'recentViewedProNum' -> value:", recentViewedProNum)
} else {
beego.Trace("Failed to load 'recentViewedProNum' -> Use default value:", recentViewedProNum)
}
recentViewedPros = make([]*recentPro, 0, recentViewedProNum)
// Get recent viewed projects from database.
proinfos, _ := models.GetRecentPros(recentViewedProNum)
for _, p := range proinfos {
// Only projects with import path length is less than 40 letters will be showed.
if len(p.Path) < 40 {
recentViewedPros = append(recentViewedPros,
&recentPro{
Path: p.Path,
Synopsis: p.Synopsis,
ViewedTime: p.ViewedTime,
IsGoRepo: p.ProName == "Go" &&
strings.Index(p.Path, ".") == -1,
})
}
}
// Initialize project tags.
labelList = strings.Split(beego.AppConfig.String("labels"), "|")
for _, s := range labelList {
labelSet += """ + s + "","
}
labelSet = labelSet[:len(labelSet)-1]
}
示例3: Post
func (this *TextMessageController) Post() {
r := this.Ctx.Request
//this.ParseForm()
r.ParseForm()
//beego.Trace("ToUserName", this.GetString("ToUserName"))
//beego.Trace("ToUserName", r.PostFormValue("ToUserName"))
//beego.Trace("MsgType", this.GetString("MsgType"))
//beego.Trace("MsgType", r.PostFormValue("MsgType"))
for k, v := range r.Form {
beego.Trace("key:", k)
beego.Trace("val:", strings.Join(v, ""))
}
//for k, v := range r.PostForm {
// beego.Trace("key:", k)
// beego.Trace("val:", strings.Join(v, ""))
//}
//for i, s := range string(this.Ctx.Input.RequestBody) {
// beego.Trace(i, ":", s, ":", string(s))
//}
//beego.Trace("body:", string(this.Ctx.Input.RequestBody))
output, _ := iconv.ConvertString(string(this.Ctx.Input.RequestBody), "utf8", "gbk")
//beego.Trace(charmap.Windows1252.NewEncoder())
//encoding.UTF8Validator.Transform()
beego.Trace(output)
this.Data["Out"] = "sdfasdfasdfasdfasdfa"
this.TplNames = "out.tpl"
}
示例4: init
func init() {
// Initialized recent viewed project list.
num, err := beego.AppConfig.Int("recentViewedProNum")
if err == nil {
recentViewedProNum = num
beego.Trace("Loaded 'recentViewedProNum' -> value:", recentViewedProNum)
} else {
beego.Trace("Failed to load 'recentViewedProNum' -> Use default value:", recentViewedProNum)
}
recentViewedPros = make([]*recentPro, 0, recentViewedProNum)
// Get recent viewed projects from database.
proinfos, _ := models.GetRecentPros(recentViewedProNum)
for _, p := range proinfos {
recentViewedPros = append(recentViewedPros,
&recentPro{
Path: p.Path,
ViewedTime: p.ViewedTime,
IsGoRepo: p.ProName == "Go",
Views: p.Views,
})
}
// Initialized language type list.
langs := strings.Split(beego.AppConfig.String("language"), "|")
names := strings.Split(beego.AppConfig.String("langNames"), "|")
langTypes = make([]*langType, 0, len(langs))
for i, v := range langs {
langTypes = append(langTypes, &langType{
Lang: v,
Name: names[i],
})
}
}
示例5: DoLogin
func (this *AuthController) DoLogin() {
this.CheckRequestFrequency(3, 15, 30)
if this.IsLogin {
this.Redirect("/", 302)
}
valid := validation.Validation{}
form := LoginForm{}
if err := this.ParseForm(&form); err != nil {
beego.Error(err)
}
b, err := valid.Valid(form)
if err != nil {
beego.Error(err)
}
if !b {
this.loginPageWithErrors(form, valid.Errors)
return
}
//用户不存在?
user := models.User{Username: form.Username, Email: form.Username}
if err := user.Read("Username"); err != nil {
if err2 := user.Read("Email"); err2 != nil {
errMsg := fmt.Sprintf("用户 %s 不存在!", form.Username)
beego.Trace(errMsg)
valid.SetError("username", errMsg)
this.loginPageWithErrors(form, valid.Errors)
return
}
}
//用户被禁止?
if user.IsBanned {
beego.Trace(fmt.Sprintf("用户%s被禁用,不能登录!", user.Username))
valid.SetError("username", "抱歉,您被禁止登录!")
this.loginPageWithErrors(form, valid.Errors)
return
}
//检查密码
if !user.VerifyPassword(form.Password) {
beego.Trace(fmt.Sprintf("%s 登录失败!", form.Username))
valid.SetError("password", "密码错误")
this.loginPageWithErrors(form, valid.Errors)
return
}
//验证全部通过
var remember bool
if form.Remember != "" {
remember = true
}
this.LogUserIn(&user, remember)
this.Redirect(GetLoginRedirectUrl(this.Ctx), 302)
return
}
示例6: Get
func (c *MainController) Get() {
// c.Data["Website"] = "beego.me"
// c.Data["Email"] = "[email protected]"
// c.TplName = "index.tpl"
c.Ctx.WriteString("appname: " + beego.AppConfig.String("appname") +
"\nhttpport: " + beego.AppConfig.String("httpport") +
"\nrunmode: " + beego.AppConfig.String("runmode"))
beego.Trace("trace 1")
beego.Info("info 1")
beego.SetLevel(beego.LevelInformational)
beego.Trace("trace 2")
beego.Info("info 2")
}
示例7: DefaultData
func DefaultData() {
o := orm.NewOrm()
var configure Configure
configure.CName = "status"
configure.CValue = "0" //0未启动,1启动,2已押注
_, err := o.Insert(&configure)
if err != nil {
beego.Error(err)
} else {
beego.Trace("初始化status……")
}
configure.CName = "prize"
configure.CValue = ""
_, err = o.Insert(&configure)
if err != nil {
beego.Error(err)
} else {
beego.Trace("初始化prize……")
}
configure.CName = "prize_url"
configure.CValue = "http://yun.baozoumanhua.com/Project/RageMaker0/images/0/5.png"
_, err = o.Insert(&configure)
if err != nil {
beego.Error(err)
} else {
beego.Trace("初始化prize_url……")
}
// 初始化赛马信息
horse := []Horse{
{Name: "Oe", Win: 0, Lose: 0},
{Name: "To", Win: 0, Lose: 0},
{Name: "Tr", Win: 0, Lose: 0},
{Name: "Fr", Win: 0, Lose: 0},
{Name: "Fe", Win: 0, Lose: 0},
{Name: "Sx", Win: 0, Lose: 0},
}
successNums, err := o.InsertMulti(1, horse)
if err != nil {
beego.Error(err)
} else {
beego.Trace("初始化" + strconv.FormatInt(successNums, 10) + "匹马……")
}
}
示例8: processLoginForm
func (this *SocialAuthController) processLoginForm(socialType social.SocialType) {
valid := validation.Validation{}
form := SocialAuthLoginForm{}
var user models.User
if err := this.ParseForm(&form); err != nil {
beego.Error(err)
}
b, err := valid.Valid(form)
if err != nil {
beego.Error(err)
}
if !b {
goto showLoginErrors
}
//用户不存在?
user = models.User{Username: form.Username, Email: form.Username}
if err := user.Read("Username"); err != nil {
if err2 := user.Read("Email"); err2 != nil {
errMsg := fmt.Sprintf("用户 %s 不存在!", form.Username)
valid.SetError("Username", errMsg)
goto showLoginErrors
}
}
//用户被禁止?
if user.IsBanned {
beego.Trace(fmt.Sprintf("用户%s被禁用,不能登录!", user.Username))
valid.SetError("Username", "抱歉,您被禁止登录!")
goto showLoginErrors
}
//检查密码
if !user.VerifyPassword(form.Password) {
beego.Trace(fmt.Sprintf("%s 登录失败!", form.Username))
valid.SetError("Password", "密码错误")
goto showLoginErrors
}
//验证全部通过
if loginRedirect, _, err := SocialAuth.ConnectAndLogin(this.Ctx, socialType, user.Id); err != nil {
beego.Error("ConnectAndLogin:", err)
goto showLoginErrors
} else {
beego.Trace("Let's redirect ", loginRedirect)
this.Redirect(loginRedirect, 302)
return
}
showLoginErrors:
this.Data["LoginForm"] = form
this.Data["LoginFormErrors"] = valid.Errors
return
}
示例9: Test_AuthController_Auth_Success
func Test_AuthController_Auth_Success(t *testing.T) {
b, _ := json.Marshal(&mocked_auth_info)
r, _ := http.NewRequest("POST", "/api/auth", bytes.NewBuffer(b))
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "Test_AuthController_Auth_Success", "Code[%d]\n%s",
w.Code, w.Body.String())
Convey("Subject: Test Auth Success Endpoint\n", t, func() {
Convey("Status code should be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The result should not be empty", func() {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
Convey("The result should be an true Success", func() {
type Success struct {
Succ bool `json:"success"`
}
var result Success
json.Unmarshal(w.Body.Bytes(), &result)
So(result == Success{true}, ShouldBeTrue)
})
Convey("The response should set session", func() {
So(strings.Contains(w.HeaderMap.Get(
http.CanonicalHeaderKey("Set-Cookie")), "beegosessionID"), ShouldBeTrue)
})
})
}
示例10: Post
func (this *ImportController) Post() {
//check islogin
session := this.GetSession("Admin")
if session == nil {
beego.Trace("session verify failed!")
this.Redirect("/", 302)
return
}
saveFileName := "temp" + strconv.FormatInt(int64(time.Now().UnixNano()), 10) + ".xlsx"
beego.Debug("saveFileName=", saveFileName)
this.SaveToFile("file", saveFileName)
devices := make([]models.Deviceinfo, 0)
xlFile, err := xlsx.OpenFile(saveFileName)
if err != nil {
beego.Error("Open excel file!", err)
}
for _, sheet := range xlFile.Sheets {
for _, row := range sheet.Rows {
for _, cell := range row.Cells {
device := models.Deviceinfo{
Mac: cell.String(),
ImportTime: time.Now(),
InvalidTime: time.Now().Add(3 * 30 * 24 * time.Hour),
}
//check mac address format
if !CheckMacFormat(device.Mac) {
beego.Info(device.Mac, "not a mac address!")
continue
}
//if the mac address had existed,skip it
if models.ImportDeviceCheck(&device) {
beego.Info(device.Mac, "had been imported!")
continue
}
devices = append(devices, device)
}
}
}
//delete used file
err = os.Remove(saveFileName)
if err != nil {
beego.Error("Remove temp excel file failed!", err)
}
ok := models.ImportDevices(&devices)
if ok {
beego.Info("ImportDevices success!")
this.Redirect("/home", 301)
this.Data["IsImported"] = true
return
} else {
beego.Info("ImportDevices failed! once again")
this.Redirect("/import", 302)
return
}
}
示例11: Post
func (this *CommandController) Post() {
//检查登录状态
session := this.GetSession("Admin")
if session == nil {
beego.Trace("session verify failed!")
this.Redirect("/", 302)
return
}
//获取表单信息
mac := this.Input().Get("mac")
beego.Debug("mac=", mac)
commandContent := this.Input().Get("commandContent")
beego.Debug("commandContent=", commandContent)
//下发action
device := models.Deviceinfo{
Mac: mac,
Act: commandContent,
}
ok := models.SetAct(&device)
if !ok {
beego.Info("set action failed!")
}
//返回设备页面
this.Redirect("/home", 302)
return
}
示例12: Prepare
func (this *BaseController) Prepare() {
//Accept-Language
acceptLanguage := this.Ctx.Request.Header.Get("Accept-Language")
if len(acceptLanguage) > 4 {
acceptLanguage = acceptLanguage[:5] // Only compare first 5 letters.
if i18n.IsExist(acceptLanguage) {
Lang = acceptLanguage
}
}
if len(Lang) == 0 {
Lang = "en-US"
}
// Initialized language type list.
langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
names := strings.Split(beego.AppConfig.String("lang::names"), "|")
langTypes := make([]*langType, 0, len(langs))
for i, v := range langs {
langTypes = append(langTypes, &langType{
Lang: v,
Name: names[i],
})
}
for _, lang := range langs {
beego.Trace("Loading language: " + lang)
if err := i18n.SetMessage(lang, "lang/"+"locale_"+lang+".ini"); err != nil {
beego.Error("Fail to set message file: " + err.Error())
return
}
}
}
示例13: MountResourceFiles
/////////////////////////////////////////////////////////////
// MountResourceFiles
func MountResourceFiles(user string, project string) error {
resources := []string{"image", "sound"}
for _, res := range resources {
fromDir := beego.AppConfig.String("userdata::location") +
user + "/" +
beego.AppConfig.String("userdata::projects") + "/" +
project + "/" +
beego.AppConfig.String("userdata::"+res+"files")
toDir := beego.AppConfig.String("userdata::location") +
user + "/" + beego.AppConfig.String("userdata::"+res+"files") + "/" +
project
res, _ := exec.Command("sh", "-c", "mount | grep \""+toDir+"\"").Output()
if len(res) == 0 {
beego.Trace("MOUNTING resource", res, "of project", project, "from user", user)
if err := os.MkdirAll(toDir, os.ModePerm); err != nil {
beego.Error("Cannot create directory", toDir)
}
cmd := exec.Command("sudo", "mount", "--bind", fromDir, toDir)
err := cmd.Run()
if err != nil {
beego.Error("Cannot mount --bind ", toDir, err.Error())
}
}
}
return nil
}
示例14: processUserPasswordForm
func (this *UserController) processUserPasswordForm(user *models.User) {
valid := validation.Validation{}
userPasswordForm := UserPasswordForm{}
if err := this.ParseForm(&userPasswordForm); err != nil {
beego.Error(err)
}
_, err := valid.Valid(userPasswordForm)
if err != nil {
beego.Error(err)
this.Abort("400")
}
if !user.VerifyPassword(userPasswordForm.CurrentPassword) {
valid.SetError("CurrentPassword", "当前密码错误")
}
if len(valid.Errors) > 0 {
this.Data["UserPasswordFormValidErrors"] = valid.Errors
beego.Trace(fmt.Sprint(valid.Errors))
} else {
user.SetPassword(userPasswordForm.Password)
if err := user.Update(); err != nil {
this.Abort("500")
}
this.FlashWrite("notice", "密码已更新!")
this.Redirect(this.Ctx.Request.RequestURI, 302)
}
}
示例15: InitDb
// InitDb initializes the database.
func InitDb() {
dbName := utils.Cfg.MustValue("db", "name")
dbPwd := utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS)
// Register database.
qbs.Register("mysql", fmt.Sprintf("%v:%[email protected]%v/%v?charset=utf8&parseTime=true",
utils.Cfg.MustValue("db", "user"), dbPwd,
utils.Cfg.MustValue("db", "host"), dbName),
dbName, qbs.NewMysql())
// Connect to database.
q := connDb()
defer q.Close()
mg, err := setMg()
if err != nil {
panic("models.init -> " + err.Error())
}
defer mg.Close()
// Create data tables.
mg.CreateTableIfNotExists(new(hv.PkgInfo))
mg.CreateTableIfNotExists(new(PkgTag))
mg.CreateTableIfNotExists(new(PkgRock))
mg.CreateTableIfNotExists(new(PkgExam))
mg.CreateTableIfNotExists(new(PkgDecl))
mg.CreateTableIfNotExists(new(PkgDoc))
mg.CreateTableIfNotExists(new(PkgFunc))
mg.CreateTableIfNotExists(new(PkgImport))
beego.Trace("Initialized database ->", dbName)
}