本文整理汇总了Golang中Logger.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindCurrentUser
// 获取当前登录用户信息(常用信息)
func FindCurrentUser(username string) (user map[string]interface{}, err error) {
userLogin := model.NewUserLogin()
err = userLogin.Where("username=" + username).Find()
if err != nil {
logger.Errorf("获取用户 %s 信息失败:%s", username, err)
return
}
if userLogin.Uid == 0 {
logger.Infof("用户 %s 不存在!", username)
return
}
user = map[string]interface{}{
"uid": userLogin.Uid,
"username": userLogin.Username,
"email": userLogin.Email,
}
// 获取未读消息数
user["msgnum"] = FindNotReadMsgNum(userLogin.Uid)
// 获取角色信息
userRoleList, err := model.NewUserRole().Where("uid=" + strconv.Itoa(userLogin.Uid)).FindAll()
if err != nil {
logger.Errorf("获取用户 %s 角色 信息失败:%s", username, err)
return
}
for _, userRole := range userRoleList {
if userRole.Roleid <= model.AdminMinRoleId {
// 是管理员
user["isadmin"] = true
}
}
return
}
示例2: findUserByUniq
// 通过唯一键(uid或username)获取用户信息
func findUserByUniq(field, val string) *model.User {
user := model.NewUser()
err := user.Where(field + "=" + val).Find()
if err != nil {
logger.Errorf("获取用户 %s 信息失败:%s", val, err)
return nil
}
if user.Uid == 0 {
return nil
}
// 获取用户角色信息
userRoleList, err := model.NewUserRole().
Order("roleid ASC").Where("uid="+strconv.Itoa(user.Uid)).FindAll("uid", "roleid")
if err != nil {
logger.Errorf("获取用户 %s 角色 信息失败:%s", val, err)
return nil
}
if roleNum := len(userRoleList); roleNum > 0 {
user.Roleids = make([]int, roleNum)
user.Rolenames = make([]string, roleNum)
for i, userRole := range userRoleList {
user.Roleids[i] = userRole.Roleid
user.Rolenames[i] = Roles[userRole.Roleid-1].Name
}
}
return user
}
示例3: FindUserByUsername
// 获取单个用户信息
func FindUserByUsername(username string) *model.User {
user := model.NewUser()
err := user.Where("username=" + username).Find()
if err != nil {
logger.Errorf("获取用户 %s 信息失败:%s", username, err)
return nil
}
if user.Uid == 0 {
return nil
}
// 获取角色信息
userRoleList, err := model.NewUserRole().Where("uid=" + strconv.Itoa(user.Uid)).FindAll()
if err != nil {
logger.Errorf("获取用户 %s 角色 信息失败:%s", username, err)
return nil
}
for _, userRole := range userRoleList {
if len(user.Roleids) == 0 {
user.Rolenames = []string{model.AllRole[userRole.Roleid].Name}
} else {
user.Rolenames = append(user.Rolenames, model.AllRole[userRole.Roleid].Name)
}
}
return user
}
示例4: PostFilter
// 在逻辑处理完之后,最后展示页面
func (this *ViewFilter) PostFilter(rw http.ResponseWriter, req *http.Request) bool {
contentHtml := req.FormValue(CONTENT_TPL_KEY)
if contentHtml == "" {
return true
}
contentHtmls := strings.Split(contentHtml, ",")
for i, contentHtml := range contentHtmls {
contentHtmls[i] = config.ROOT + strings.TrimSpace(contentHtml)
}
// 为了使用自定义的模板函数,首先New一个以第一个模板文件名为模板名。
// 这样,在ParseFiles时,新返回的*Template便还是原来的模板实例
tpl, err := template.New(this.baseTplName).Funcs(funcMap).ParseFiles(append(this.commonHtmlFiles, contentHtmls...)...)
if err != nil {
logger.Errorf("解析模板出错(ParseFiles):[%q] %s\n", req.RequestURI, err)
return false
}
// 如果没有定义css和js模板,则定义之
if jsTpl := tpl.Lookup("js"); jsTpl == nil {
tpl.Parse(`{{define "js"}}{{end}}`)
}
if jsTpl := tpl.Lookup("css"); jsTpl == nil {
tpl.Parse(`{{define "css"}}{{end}}`)
}
data := GetData(req)
err = tpl.Execute(rw, data)
if err != nil {
logger.Errorf("执行模板出错(Execute):[%q] %s\n", req.RequestURI, err)
}
return true
}
示例5: getOrderBook
func (w *Huobi) getOrderBook(symbol string) (ret bool, hbOrderBook OrderBook) {
// init to false
ret = false
var huobisymbol string
if symbol == "btc_cny" {
huobisymbol = "huobibtccny"
} else {
huobisymbol = "huobiltccny"
logger.Fatal("huobi does not support LTC by now, wait for huobi provide it.", huobisymbol)
return
}
rnd := util.RandomString(20)
now := time.Now().UnixNano() / 1000000
req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_trade_detail"], rnd, now, now), nil)
if err != nil {
logger.Fatal(err)
return
}
req.Header.Set("Referer", Config["base_url"])
req.Header.Add("Connection", "keep-alive")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
req.Header.Add("Accept-Encoding", "identity")
resp, err := http.DefaultClient.Do(req)
if err != nil {
logger.Traceln(err)
logger.Traceln(req)
logger.Traceln(resp)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
logger.Errorf("HTTP returned status %v", resp)
return
}
var body string
contentEncoding := resp.Header.Get("Content-Encoding")
logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding)
switch contentEncoding {
case "gzip":
body = util.DumpGZIP(resp.Body)
default:
bodyByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Errorln("read the http stream failed")
return
} else {
body = string(bodyByte)
ioutil.WriteFile("cache/OrderBook.json", bodyByte, 0644)
}
}
return w.analyzeOrderBook(body)
}
示例6: Tick
//entry call
func Tick(tradeAPI TradeAPI, records []Record) bool {
strategyName := Option["strategy"]
strategy, ok := strategys[strategyName]
if !ok {
logger.Errorf("sql: unknown strategy %q (forgotten import? private strategy?)", strategyName)
return false
}
// length := len(records)
// //
// if length == 0 {
// logger.Errorln("warning:detect exception data", len(records))
// return false
// }
// //check exception data in trade center
// if checkException(records[length-2], records[length-1]) == false {
// logger.Errorln("detect exception data of trade center",
// records[length-2].Close, records[length-1].Close, records[length-1].Volumn)
// return false
// }
gTradeAPI = tradeAPI
return strategy.Tick(records)
}
示例7: Login
// 登录;成功返回用户登录信息(user_login)
func Login(username, passwd string) (*model.UserLogin, error) {
userLogin := model.NewUserLogin()
err := userLogin.Where("username=" + username + " OR email=" + username).Find()
if err != nil {
logger.Errorf("用户 %s 登录错误:%s", username, err)
return nil, errors.New("内部错误,请稍后再试!")
}
// 校验用户
if userLogin.Uid == 0 {
logger.Infof("用户名 %s 不存在", username)
return nil, ErrUsername
}
passcode := userLogin.GetPasscode()
md5Passwd := util.Md5(passwd + passcode)
logger.Debugf("passwd: %s, passcode: %s, md5passwd: %s, dbpasswd: %s", passwd, passcode, md5Passwd, userLogin.Passwd)
if md5Passwd != userLogin.Passwd {
logger.Infof("用户名 %s 填写的密码错误", username)
return nil, ErrPasswd
}
// 登录,活跃度+1
go IncUserWeight("uid="+strconv.Itoa(userLogin.Uid), 1)
return userLogin, nil
}
示例8: RecordLoginTime
// 记录用户最后登录时间
func RecordLoginTime(username string) error {
userLogin := model.NewUserLogin()
err := userLogin.Set("login_time=" + time.Now().Format("2006-01-02 15:04:05")).Where("username=" + username).Update()
if err != nil {
logger.Errorf("记录用户 %s 登录时间错误:%s", username, err)
}
return err
}
示例9: FindTopic
// 获取单个 Topic 信息(用于编辑)
func FindTopic(tid string) *model.Topic {
topic := model.NewTopic()
err := topic.Where("tid=?", tid).Find()
if err != nil {
logger.Errorf("FindTopic [%s] error:%s\n", tid, err)
}
return topic
}
示例10: FindResourceById
// 获取单个 Resource 信息(用于编辑)
func FindResourceById(id string) *model.Resource {
resource := model.NewResource()
err := resource.Where("id=?", id).Find()
if err != nil {
logger.Errorf("FindResourceById [%s] error:%s\n", id, err)
}
return resource
}
示例11: main
func main() {
// Metron is intended to be light-weight so we occupy only one core
runtime.GOMAXPROCS(1)
flag.Parse()
config, err := config.ParseConfig(*configFilePath)
if err != nil {
panic(fmt.Errorf("Unable to parse config: %s", err))
}
logger := logger.NewLogger(*debug, *logFilePath, "metron", config.Syslog)
statsStopChan := make(chan struct{})
batcher, eventWriter := initializeMetrics(config, statsStopChan, logger)
go func() {
err := http.ListenAndServe(net.JoinHostPort("localhost", pprofPort), nil)
if err != nil {
logger.Errorf("Error starting pprof server: %s", err.Error())
}
}()
logger.Info("Startup: Setting up the Metron agent")
marshaller, err := initializeDopplerPool(config, batcher, logger)
if err != nil {
panic(fmt.Errorf("Could not initialize doppler connection pool: %s", err))
}
messageTagger := tagger.New(config.Deployment, config.Job, config.Index, marshaller)
aggregator := messageaggregator.New(messageTagger, logger)
eventWriter.SetWriter(aggregator)
dropsondeUnmarshaller := eventunmarshaller.New(aggregator, batcher, logger)
metronAddress := fmt.Sprintf("127.0.0.1:%d", config.IncomingUDPPort)
dropsondeReader, err := networkreader.New(metronAddress, "dropsondeAgentListener", dropsondeUnmarshaller, logger)
if err != nil {
panic(fmt.Errorf("Failed to listen on %s: %s", metronAddress, err))
}
logger.Info("metron started")
go dropsondeReader.Start()
dumpChan := signalmanager.RegisterGoRoutineDumpSignalChannel()
killChan := signalmanager.RegisterKillSignalChannel()
for {
select {
case <-dumpChan:
signalmanager.DumpGoRoutine()
case <-killChan:
logger.Info("Shutting down")
close(statsStopChan)
return
}
}
}
示例12: ModifyComment
func ModifyComment(cid, content string) (errMsg string, err error) {
err = model.NewComment().Set("content=?", content).Where("cid=" + cid).Update()
if err != nil {
logger.Errorf("更新评论内容 【%s】 失败:%s\n", cid, err)
errMsg = "对不起,服务器内部错误,请稍后再试!"
return
}
return
}
示例13: UpdateUserStatus
// UpdateUserStatus 更新用户状态
func UpdateUserStatus(uid, status int) {
setClause := "status=" + strconv.Itoa(status)
err := model.NewUser().Set(setClause).Where("uid=?", uid).Update()
if err != nil {
logger.Errorf("更新用户 【%s】 状态失败:%s", uid, err)
return
}
return
}
示例14: UpdatePasswd
// 更新用户密码(用户名或email)
func UpdatePasswd(username, passwd string) (string, error) {
userLogin := model.NewUserLogin()
passwd = userLogin.GenMd5Passwd(passwd)
err := userLogin.Set("passwd=" + passwd + ",passcode=" + userLogin.GetPasscode()).Where("username=" + username + " OR email=" + username).Update()
if err != nil {
logger.Errorf("用户 %s 更新密码错误:%s", username, err)
return "对不起,内部服务错误!", err
}
return "", nil
}
示例15: RunCreateVm
func RunCreateVm(ctx context.Context, vmDeviceId uint) error {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
return errors.New("内部服务器错误")
}
logger, ok := middleware.LoggerFromContext(ctx)
if !ok {
return errors.New("内部服务器错误")
}
vmDevice, err := repo.GetVmDeviceById(vmDeviceId)
if err != nil {
return err
}
device, err := repo.GetDeviceById(vmDevice.DeviceID)
if err != nil {
return err
}
var cmdFormat = `LANG=C virt-install --connect qemu+ssh://[email protected]%s/system \
--name=%s \
--os-type=windows \
--vcpus=%d \
--ram=%d \
--hvm \
--boot hd,network,menu=on \
--accelerate \
--graphics vnc,listen=0.0.0.0,port=%s \
--noautoconsole \
--autostart \
--network bridge=br0,model=virtio,mac=%s \
--disk path=/dev/VolGroup0/%s,device=disk,bus=virtio,cache=none,sparse=false,format=raw`
var cmd = fmt.Sprintf(cmdFormat,
device.Ip,
vmDevice.Hostname,
vmDevice.CpuCoresNumber,
vmDevice.MemoryCurrent,
vmDevice.VncPort,
vmDevice.Mac,
vmDevice.Hostname)
logger.Debugf("create vm:%s", cmd)
var runResult = "执行脚本:\n" + cmd
bytes, err := util.ExecScript(cmd)
logger.Debugf("create result:%s", string(bytes))
runResult += "\n\n" + "执行结果:\n" + string(bytes)
if err != nil {
logger.Errorf("create error:%s", err.Error())
runResult += "\n\n" + "错误信息:\n" + err.Error()
return errors.New(runResult)
}
return nil
}