本文整理匯總了Golang中github.com/fluffle/goirc/logging.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Associate
// Associates an already known nick with an already known channel.
func (st *stateTracker) Associate(c, n string) *ChanPrivs {
st.mu.Lock()
defer st.mu.Unlock()
nk, nok := st.nicks[n]
ch, cok := st.chans[c]
if !cok {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Associate(): channel %s not found in "+
"internal state.", c)
return nil
} else if !nok {
logging.Error("Tracker.Associate(): nick %s not found in "+
"internal state.", n)
return nil
} else if _, ok := nk.isOn(ch); ok {
logging.Warn("Tracker.Associate(): %s already on %s.",
nk, ch)
return nil
}
cp := new(ChanPrivs)
ch.addNick(nk, cp)
nk.addChannel(ch, cp)
return cp.Copy()
}
示例2: Dissociate
// Dissociates an already known nick from an already known channel.
// Does some tidying up to stop tracking nicks we're no longer on
// any common channels with, and channels we're no longer on.
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
if ch == nil || nk == nil {
logging.Error("Tracker.Dissociate(): passed nil values :-(")
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Dissociate(): channel %s not found in "+
"(or differs from) internal state.", ch.Name)
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
logging.Error("Tracker.Dissociate(): nick %s not found in "+
"(or differs from) internal state.", nk.Nick)
} else if _, ok := nk.IsOn(ch); !ok {
logging.Warn("Tracker.Dissociate(): %s not on %s.",
nk.Nick, ch.Name)
} else if nk == st.me {
// I'm leaving the channel for some reason, so it won't be tracked.
st.delChannel(ch)
} else {
// Remove the nick from the channel and the channel from the nick.
ch.delNick(nk)
nk.delChannel(ch)
if len(nk.chans) == 0 {
// We're no longer in any channels with this nick.
st.delNick(nk)
}
}
}
示例3: Associate
// Associates an already known nick with an already known channel.
func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
if ch == nil || nk == nil {
logging.Error("Tracker.Associate(): passed nil values :-(")
return nil
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Associate(): channel %s not found in "+
"(or differs from) internal state.", ch.Name)
return nil
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
logging.Error("Tracker.Associate(): nick %s not found in "+
"(or differs from) internal state.", nk.Nick)
return nil
} else if _, ok := nk.IsOn(ch); ok {
logging.Warn("Tracker.Associate(): %s already on %s.",
nk.Nick, ch.Name)
return nil
}
cp := new(ChanPrivs)
ch.addNick(nk, cp)
nk.addChannel(ch, cp)
return cp
}
示例4: Dissociate
// Dissociates an already known nick from an already known channel.
// Does some tidying up to stop tracking nicks we're no longer on
// any common channels with, and channels we're no longer on.
func (st *stateTracker) Dissociate(c, n string) {
st.mu.Lock()
defer st.mu.Unlock()
nk, nok := st.nicks[n]
ch, cok := st.chans[c]
if !cok {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Dissociate(): channel %s not found in "+
"internal state.", c)
} else if !nok {
logging.Error("Tracker.Dissociate(): nick %s not found in "+
"internal state.", n)
} else if _, ok := nk.isOn(ch); !ok {
logging.Warn("Tracker.Dissociate(): %s not on %s.",
nk.nick, ch.name)
} else if nk == st.me {
// I'm leaving the channel for some reason, so it won't be tracked.
st.delChannel(ch)
} else {
// Remove the nick from the channel and the channel from the nick.
ch.delNick(nk)
nk.delChannel(ch)
if len(nk.chans) == 0 {
// We're no longer in any channels with this nick.
st.delNick(nk)
}
}
}
示例5: remove
func (hs *hSet) remove(hn *hNode) {
hs.Lock()
defer hs.Unlock()
l, ok := hs.set[hn.event]
if !ok {
logging.Error("Removing node for unknown event '%s'", hn.event)
return
}
if hn.next == nil {
l.end = hn.prev
} else {
hn.next.prev = hn.prev
}
if hn.prev == nil {
l.start = hn.next
} else {
hn.prev.next = hn.next
}
hn.next = nil
hn.prev = nil
hn.set = nil
if l.start == nil || l.end == nil {
delete(hs.set, hn.event)
}
}
示例6: pushAuthHTTP
func pushAuthHTTP(rw http.ResponseWriter, req *http.Request) {
if err := req.ParseForm(); err != nil {
http.Redirect(rw, req, pushFailureURL("parse"), 302)
return
}
if req.FormValue("error") != "" {
http.Redirect(rw, req, pushFailureURL("denied"), 302)
return
}
id := req.FormValue("state")
s := pc.GetByB64(id)
if id == "" || s == nil {
http.Redirect(rw, req, pushFailureURL("nostate"), 302)
return
}
code := req.FormValue("code")
if code == "" {
http.Redirect(rw, req, pushFailureURL("notoken"), 302)
return
}
tok, err := push.Exchange(code)
if err != nil {
logging.Error("Failed to get access token for %s: %v", s.Nick, err)
http.Redirect(rw, req, pushFailureURL("exchange"), 302)
return
}
s.Token = tok
pc.SetState(s)
http.Redirect(rw, req, pushDeviceURL(id), 302)
}
示例7: dumpBans
func (p *Plugin) dumpBans(target string) {
num := 0
// Fetch ban list
banlist, err := p.mode.Bans(target)
if err != nil {
logging.Warn("Could not fetch ban list, old bans won't get handled")
return
}
tbmgr := p.ensureTemporaryBanManager(target)
// Save only bans from us
for _, ban := range banlist {
if ban.Nick != p.bot.Me().Nick {
// Not a ban from us (going by the nickname at least)
isOldHostmask := false
for _, hostmask := range p.OldHostmasks {
// TODO - Test this implementation
hostmask = regexp.QuoteMeta(hostmask)
hostmask = strings.Replace(hostmask, "\\*", ".*", -1)
hostmask = strings.Replace(hostmask, "\\?", ".?", -1)
if matched, err := regexp.MatchString(hostmask, ban.Src); matched {
isOldHostmask = true
break
} else if err != nil {
logging.Error("vpnbot.Plugin: dumpBans regular expression failed: %v",
err)
break
}
}
if !isOldHostmask {
// Not a ban from an old hostmask either
continue
}
}
if _, ok := tbmgr.Get(ban.Hostmask); ok {
// We already have this ban saved
continue
}
if err := tbmgr.Add(NewTemporaryBan(
ban.Nick,
ban.Hostmask,
ban.Src,
"Migrated old ban",
48*time.Hour+ban.Timestamp.Sub(time.Now()))); err != nil {
logging.Warn("Could not migrate ban on %v: %v", ban.Hostmask, err)
}
num++
}
if num > 0 {
p.syncBans(target)
logging.Info("Migrated %v bans", num)
}
}
示例8: get
func (ns *namespace) get(key string) interface{} {
var e Entry
if err := ns.Get(ns.K(key), &e); err != nil && err != mgo.ErrNotFound && err != boltdb.ErrTxNotWritable {
logging.Error("Couldn't get config entry for ns=%q key=%q: %v", ns.ns, key, err)
return nil
}
return e.Value
}
示例9: delNick
func (st *stateTracker) delNick(nk *Nick) {
if nk == st.me {
// Shouldn't get here => internal state tracking code is fubar.
logging.Error("Tracker.DelNick(): TRYING TO DELETE ME :-(")
return
}
delete(st.nicks, nk.Nick)
for ch, _ := range nk.chans {
nk.delChannel(ch)
ch.delNick(nk)
if len(ch.nicks) == 0 {
// Deleting a nick from tracking shouldn't empty any channels as
// *we* should be on the channel with them to be tracking them.
logging.Error("Tracker.delNick(): deleting nick %s emptied "+
"channel %s, this shouldn't happen!", nk.Nick, ch.Name)
}
}
}
示例10: Migrate
func Migrate() error {
ms.Lock()
defer ms.Unlock()
ms.db.Init(Bolt, COLLECTION, nil)
failed := []string{}
for coll, m := range ms.migrators {
if m.migrated {
continue
}
logging.Debug("Migrating %q.", coll)
if err := m.Migrate(); err != nil {
logging.Error("Migrating %q failed: %v", coll, err)
failed = append(failed, coll)
continue
}
if differ, ok := m.Migrator.(Differ); ok {
before, after, err := differ.Diff()
if err != nil {
logging.Error("Diffing %q failed: %v", coll, err)
failed = append(failed, coll)
continue
}
sort.Strings(before)
sort.Strings(after)
unified, err := diff.Unified(before, after)
if err != nil {
logging.Error("Migration diff: %v\n%s", err, strings.Join(unified, "\n"))
failed = append(failed, coll)
continue
}
}
if err := ms.db.Put(K{{"collection", coll}}, &done{true}); err != nil {
logging.Warn("Setting migrated status for %q: %v", coll, err)
}
m.migrated = true
}
if len(failed) > 0 {
return fmt.Errorf("migration failed for: \"%s\"",
strings.Join(failed, "\", \""))
}
return nil
}
示例11: pushDeviceHTTP
func pushDeviceHTTP(rw http.ResponseWriter, req *http.Request) {
if err := req.ParseForm(); err != nil {
http.Redirect(rw, req, pushFailureURL("parse"), 302)
return
}
id := req.FormValue("state")
s := pc.GetByB64(id)
if id == "" || s == nil {
http.Redirect(rw, req, pushFailureURL("nostate"), 302)
return
}
if req.Method == "POST" {
if s.Iden = req.FormValue("iden"); s.Iden == "" {
http.Redirect(rw, req, pushFailureURL("noiden"), 302)
return
}
s.Pin = fmt.Sprintf("%06x", rand.Intn(1e6))
if err := push.Confirm(s); err != nil {
logging.Error("Failed to send confirmation push for %s: %v", s.Nick, err)
http.Redirect(rw, req, pushFailureURL("push"), 302)
return
}
pc.SetState(s)
http.Redirect(rw, req, pushSuccessURL(), 302)
return
}
// get device list and print a form
devs, err := push.GetDevices(s)
if err != nil {
logging.Error("Failed to get devices for %s: %v", s.Nick, err)
http.Redirect(rw, req, pushFailureURL("device"), 302)
return
}
if len(devs) == 0 {
strings.NewReader(pushNoDeviceHTML).WriteTo(rw)
return
}
if err = pushDeviceTmpl.Execute(rw, &pushDevice{id, devs}); err != nil {
logging.Error("Template execution failed: %v", err)
// assuming here that failure occurred because we couldn't write
return
}
}
示例12: Init
func Init() *Collection {
pc := &Collection{db.Init().C(COLLECTION)}
if err := pc.EnsureIndex(mgo.Index{
Key: []string{"nick"},
Unique: true,
}); err != nil {
logging.Error("Couldn't create an index on push: %s", err)
}
return pc
}
示例13: write
// Write a \r\n terminated line of output to the connected server,
// using Hybrid's algorithm to rate limit if conn.cfg.Flood is false.
func (conn *Conn) write(line string) {
if !conn.cfg.Flood {
if t := conn.rateLimit(len(line)); t != 0 {
// sleep for the current line's time value before sending it
logging.Info("irc.rateLimit(): Flood! Sleeping for %.2f secs.",
t.Seconds())
<-time.After(t)
}
}
if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
logging.Error("irc.send(): %s", err.Error())
conn.shutdown()
return
}
if err := conn.io.Flush(); err != nil {
logging.Error("irc.send(): %s", err.Error())
conn.shutdown()
return
}
logging.Debug("-> %s", line)
}
示例14: isAdmin
func (plugin *Plugin) isAdmin(mask string) bool {
for _, adminmask := range plugin.Admins {
// TODO - Test this implementation
adminmask = regexp.QuoteMeta(adminmask)
adminmask = strings.Replace(adminmask, "\\*", ".*", -1)
adminmask = strings.Replace(adminmask, "\\?", ".?", -1)
if matched, err := regexp.MatchString(adminmask, mask); matched {
return true
} else if err != nil {
logging.Error("vpnbot.Plugin: isAdmin regular expression failed: %v",
err)
break
}
}
return false
}
示例15: send
// send is started as a goroutine after a connection is established.
// It shuttles data from the output channel to write(), and is killed
// when Conn.die is closed.
func (conn *Conn) send() {
for {
select {
case line := <-conn.out:
if err := conn.write(line); err != nil {
logging.Error("irc.send(): %s", err.Error())
// We can't defer this, because shutdown() waits for it.
conn.wg.Done()
conn.shutdown()
return
}
case <-conn.die:
// control channel closed, bail out
conn.wg.Done()
return
}
}
}