當前位置: 首頁>>代碼示例>>Golang>>正文


Golang deferconsole.Errorf函數代碼示例

本文整理匯總了Golang中github.com/repbin/repbin/deferconsole.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Put

// Put stores a message in the message store WITHOUT notifying the notify backend
func (store Store) Put(msgStruct *structs.MessageStruct, signerStruct *structs.SignerStruct, message []byte) error {
	// Check if message exists
	if store.db.MessageKnown(&msgStruct.MessageID) {
		return ErrDuplicate
	}
	// Check if signer exists, load last from signer
	_, signerLoaded, _ := store.db.SelectSigner(&signerStruct.PublicKey)
	if signerLoaded != nil {
		// Old signer is better
		if signerLoaded.Bits > signerStruct.Bits {
			signerStruct.Bits = signerLoaded.Bits
			signerStruct.Nonce = signerLoaded.Nonce
			signerStruct.MaxMessagesPosted = signerLoaded.MaxMessagesPosted
			signerStruct.MaxMessagesRetained = signerLoaded.MaxMessagesRetained
		}
		// Update post data
		signerStruct.MessagesPosted = signerLoaded.MessagesPosted
		signerStruct.MessagesRetained = signerLoaded.MessagesRetained
	}
	// Verify signer
	if signerStruct.MessagesPosted >= signerStruct.MaxMessagesPosted {
		return ErrPostLimit
	}
	if signerStruct.MessagesRetained >= signerStruct.MaxMessagesRetained {
		// Retention is changed by expiring messages
		return ErrPostLimit
	}
	msgStruct.PostTime = uint64(CurrentTime())
	msgStruct.ExpireTime = uint64(uint64(CurrentTime()) + signerStruct.ExpireTarget)
	if msgStruct.ExpireTime < msgStruct.ExpireRequest {
		msgStruct.ExpireTime = msgStruct.ExpireRequest
	}
	// Update signer
	err := store.db.InsertOrUpdateSigner(signerStruct)
	if err != nil {
		log.Errorf("messagestore, update signer: %s", err)
	}
	// Write message. Message is prefixed by encoded messageStruct
	storeID, err := store.db.InsertMessage(msgStruct)
	if err != nil {
		log.Errorf("messagestore, write message (DB): %s", err)
		return err
	}
	store.db.LearnMessage(&msgStruct.MessageID)
	err = store.db.InsertBlob(storeID, &msgStruct.MessageID, &signerStruct.PublicKey, msgStruct.OneTime, message)
	if err != nil {
		log.Errorf("messagestore, write message (Blob): %s", err)
		return err
	}
	if !msgStruct.OneTime && msgStruct.Sync {
		err := store.db.AddToGlobalIndex(storeID)
		if err != nil {
			log.Errorf("messagestore, globalindex append: %s", err)
		}
	}
	return nil
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:58,代碼來源:put.go

示例2: GetNotify

// GetNotify receives notifications.
func (ms MessageServer) GetNotify(w http.ResponseWriter, r *http.Request) {
	var proof [keyproof.ProofTokenSize]byte
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["auth"]; ok {
			if len(v[0]) > keyproof.ProofTokenMax {
				io.WriteString(w, "ERROR: Bad Param\n")
				return
			}
			auth := utils.B58decode(v[0])
			if auth == nil || len(auth) > keyproof.ProofTokenSize {
				io.WriteString(w, "ERROR: Bad Param\n")
				return
			}
			copy(proof[:], auth)
			ok, timeStamp, senderPubKey := keyproof.VerifyProofToken(&proof, ms.TokenPubKey)
			if !ok {
				io.WriteString(w, "ERROR: Authentication failure\n")
				if senderPubKey == nil {
					log.Errorf("VerifyProofToken failed: (proof) %s\n", utils.B58encode(proof[:]))
				} else {
					log.Errorf("VerifyProofToken failed: (pubkey) %s\n", utils.B58encode(senderPubKey[:]))
				}
				return
			}
			// verify that we know the peer
			url := ms.PeerURL(senderPubKey)
			if url == "" {
				io.WriteString(w, "ERROR: Bad peer\n")
				log.Errorf("Notify, bad peer: %s\n", utils.B58encode(senderPubKey[:]))
				return
			}
			now := CurrentTime()
			// Test too old, too young
			if enforceTimeOuts && (now > timeStamp+DefaultAuthTokenAge+ms.MaxTimeSkew || now < timeStamp-DefaultAuthTokenAge-ms.MaxTimeSkew) {
				io.WriteString(w, "ERROR: Authentication expired\n")
				log.Errorf("VerifyProofToken replay by %s\n", url)
				return
			}
			ok, signedToken := keyproof.CounterSignToken(&proof, ms.TokenPubKey, ms.TokenPrivKey)
			if !ok {
				io.WriteString(w, "ERROR: Authentication failure\n")
				return
			}
			ms.DB.UpdatePeerAuthToken(senderPubKey, signedToken)
			log.Debugf("Notified by %s\n", url)
			io.WriteString(w, "SUCCESS: Notified\n")
			return
		}
	}
	io.WriteString(w, "ERROR: Missing Param\n")
	return
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:55,代碼來源:notify.go

示例3: LoadPeers

// LoadPeers from file.
func (ms MessageServer) LoadPeers() {
	var prePeerlist PeerListEncoded
	var myPeerURLs []string
	myPeers := make(PeerList)
	peersEncoded, err := ioutil.ReadFile(ms.PeerFile)
	if err != nil {
		example := make(PeerListEncoded, 1)
		example[0].PubKey = "Example ed25519 public key encoded in base58"
		example[0].URL = exampleURL
		dat, _ := json.MarshalIndent(example, "", "    ")
		_ = dat
		err := ioutil.WriteFile(ms.PeerFile, dat, 0600)
		if err != nil {
			log.Errorf("Could not write peerfile: %s\n", err)
			return
		}
		log.Debugs("Example peerfile written\n")
		return
	}
	err = json.Unmarshal(peersEncoded, &prePeerlist)
	if err != nil {
		log.Errorf("Could not read peerfile: %s\n", err)
		return
	}
	if ms.AddToPeer && !ms.HubOnly {
		myPeerURLs = append(myPeerURLs, ms.URL)
	}
	for _, p := range prePeerlist {
		if p.URL != exampleURL {
			var tkey [ed25519.PublicKeySize]byte
			t := utils.B58decode(p.PubKey)
			copy(tkey[:], t)
			if *ms.TokenPubKey != tkey || debug {
				myPeers[tkey] = Peer{
					URL:    p.URL,
					PubKey: tkey,
				}
				if !p.IsHub {
					myPeerURLs = append(myPeerURLs, p.URL)
				}
				// Create Peer Index File
				ms.DB.TouchPeer(&tkey)
			}
		}
	}
	defer ms.setPeerURLs(myPeerURLs)
	systemPeersMutex.Lock()
	defer systemPeersMutex.Unlock()
	systemPeers = myPeers
	log.Debugs("Peers loaded\n")
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:52,代碼來源:notifybackend.go

示例4: GetPeerStat

// GetPeerStat returns the last entry of peer statistics for pubkey
func (store Store) GetPeerStat(pubkey *[ed25519.PublicKeySize]byte) *structs.PeerStruct {
	if store.peersindex.Index(pubkey[:]).Exists() {
		last := store.peersindex.Index(pubkey[:]).GetLast()
		if last == nil {
			log.Errorf("Peer last nil: %x\n", *pubkey)
			return nil
		}
		peerStat := structs.PeerStructDecode(last)
		if peerStat == nil {
			log.Errorf("Peer stat nil: %x\n", *pubkey)
			return nil
		}
		return peerStat
	}
	return nil
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:17,代碼來源:peers.go

示例5: GetPeerStat

// GetPeerStat returns the last entry of peer statistics for pubkey
func (store Store) GetPeerStat(pubkey *[ed25519.PublicKeySize]byte) *structs.PeerStruct {
	st, err := store.db.SelectPeer(pubkey)
	if err != nil {
		log.Errorf("GetPeerStat: %s, %s\n", err, utils.B58encode(pubkey[:]))
		return nil
	}
	return st
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:9,代碼來源:peers.go

示例6: LoadConfigFile

// LoadConfigFile loads configuration from a file
func LoadConfigFile(file string) (conf ConfigVariables, err error) {
	data, err := utils.MaxReadFile(409600, file)
	if err != nil {
		log.Errorf("Cannot load config from file: %s\n", file)
		return conf, err
	}
	if err := json.Unmarshal(data, &conf); err != nil {
		return conf, err
	}
	return conf, nil
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:12,代碼來源:utils.go

示例7: UpdatePeerAuthToken

// UpdatePeerAuthToken updates the peer record when a new auth token has been received
func (store Store) UpdatePeerAuthToken(senderPubKey *[ed25519.PublicKeySize]byte, signedToken *[keyproof.ProofTokenSignedSize]byte) {
	if store.peersindex.Index(senderPubKey[:]).Exists() {
		store.peersindex.Index(senderPubKey[:]).Update(func(tx fileback.Tx) error {
			last := tx.GetLast()
			if last == nil {
				log.Errorf("Peer last nil: %x\n", *senderPubKey)
				return nil
			}
			peerStat := structs.PeerStructDecode(last)
			if peerStat == nil {
				log.Errorf("Peer stat nil: %x\n", *senderPubKey)
				return nil
			}
			peerStat.LastNotifyFrom = uint64(time.Now().Unix())
			peerStat.AuthToken = *signedToken
			tx.Append(peerStat.Encode().Fill())
			return nil
		})
	}
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:21,代碼來源:peers.go

示例8: Delete

// Delete implements the delete call for messages.
func (ms MessageServer) Delete(w http.ResponseWriter, r *http.Request) {
	var messageID *[message.MessageIDSize]byte
	var privateKey *message.Curve25519Key
	for i := 0; i < 4; i++ {
		ms.RandomSleep() // Let's not give instant gratification here
	}
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["messageid"]; ok {
			t := utils.B58decode(v[0])
			if len(t) < message.MessageIDSize || len(t) > message.MessageIDSize {
				io.WriteString(w, "ERROR: Bad parameter\n")
				return
			}
			messageID = new([message.MessageIDSize]byte)
			copy(messageID[:], t)
		}
		if v, ok := getValues["privkey"]; ok {
			t := utils.B58decode(v[0])
			if len(t) < message.Curve25519KeySize || len(t) > message.Curve25519KeySize {
				io.WriteString(w, "ERROR: Bad parameter\n")
				return
			}
			privateKey = new(message.Curve25519Key)
			copy(privateKey[:], t)
		}
		if privateKey != nil && messageID != nil {
			publicKey := message.GenPubKey(privateKey)
			err := ms.DB.PreExpire(messageID, publicKey)
			if err == nil {
				log.Errorf("Message censored: %x, asshole.\n", *messageID)
				io.WriteString(w, "SUCCESS: If you want to call it that\n")
				return
			}
			log.Errorf("Message censoring failed! %s\n", err)
		}
	}
	io.WriteString(w, "ERROR: Missing parameters\n")
	return
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:42,代碼來源:delete.go

示例9: UpdatePeerFetchStat

// UpdatePeerFetchStat writes fetch-specific data
func (store Store) UpdatePeerFetchStat(pubkey *[ed25519.PublicKeySize]byte, lastFetch, lastPos, lastErrors uint64) {
	if store.peersindex.Index(pubkey[:]).Exists() {
		store.peersindex.Index(pubkey[:]).Update(func(tx fileback.Tx) error {
			last := tx.GetLast()
			if last == nil {
				log.Errorf("Peer last nil: %x\n", *pubkey)
				return nil
			}
			peerStat := structs.PeerStructDecode(last)
			if peerStat == nil {
				log.Errorf("Peer stat nil: %x\n", *pubkey)
				return nil
			}
			peerStat.LastFetch = lastFetch
			peerStat.LastPosition = lastPos
			peerStat.ErrorCount = lastErrors
			tx.Append(peerStat.Encode().Fill())
			return nil
		})
	}
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:22,代碼來源:peers.go

示例10: ExpireFromIndex

// ExpireFromIndex reads the expire index and expires messages as they are recorded
func (store Store) ExpireFromIndex() {
	// ExpireRun
	delMessages, err := store.db.SelectMessageExpire(CurrentTime())
	if err != nil {
		log.Errorf("ExpireFromIndex, SelectMessageExpire: %s\n", err)
		return
	}
	for _, msg := range delMessages {
		err := store.db.DeleteBlob(&msg.MessageID)
		if err != nil {
			log.Errorf("ExpireFromIndex, DeleteBlob: %s %s\n", err, utils.B58encode(msg.MessageID[:]))
			continue
		}
		err = store.db.DeleteMessageByID(&msg.MessageID)
		if err != nil {
			log.Errorf("ExpireFromIndex, DeleteMessageByID: %s %s\n", err, utils.B58encode(msg.MessageID[:]))
		}
	}
	_, _, err = store.db.ExpireSigners(MaxAgeSigners)
	if err != nil {
		log.Errorf("ExpireFromIndex, ExpireSigners: %s\n", err)
	}
	err = store.db.ExpireMessageCounter(MaxAgeRecipients)
	if err != nil {
		log.Errorf("ExpireFromIndex, ExpireMessageCounter: %s\n", err)
	}
	err = store.db.ForgetMessages(CurrentTime() - MaxAgeRecipients)
	if err != nil {
		log.Errorf("ExpireFromIndex, ForgetMessages: %s\n", err)
	}
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:32,代碼來源:expire.go

示例11: UpdatePeerNotification

// UpdatePeerNotification updates the peer stat after notification send
func (store Store) UpdatePeerNotification(pubkey *[ed25519.PublicKeySize]byte, hasError bool) {
	if store.peersindex.Index(pubkey[:]).Exists() {
		store.peersindex.Index(pubkey[:]).Update(func(tx fileback.Tx) error {
			last := tx.GetLast()
			if last == nil {
				log.Errorf("Peer last nil: %x\n", *pubkey)
				return nil
			}
			peerStat := structs.PeerStructDecode(last)
			if peerStat == nil {
				log.Errorf("Peer stat nil: %x\n", *pubkey)
				return nil
			}
			peerStat.LastNotifySend = uint64(time.Now().Unix())
			if hasError {
				peerStat.ErrorCount++
			}
			tx.Append(peerStat.Encode().Fill())
			return nil
		})
	}
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:23,代碼來源:peers.go

示例12: CmdGenKey

// CmdGenKey generates a long-term public key
func CmdGenKey() int {
	privkey, err := message.GenLongTermKey(OptionsVar.Hidden, OptionsVar.Sync)
	if err != nil {
		log.Errorf("Key generation error:%s\n", err)
		return 1
	}
	pubkey := message.GenPubKey(privkey)
	log.Dataf("STATUS (PrivateKey):\t%s\n", utils.B58encode(privkey[:]))
	// log.Dataf("STATUS (PublicKey):\t%s\n", utils.B58encode(pubkey[:]))
	log.Printf("PRIVATE key: %s\n\n", utils.B58encode(privkey[:]))
	// log.Printf("Public key: %s\n", utils.B58encode(pubkey[:]))
	_ = pubkey
	return 0
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:15,代碼來源:genkey.go

示例13: CmdSTM

// CmdSTM does an STM run to specific server and from specific stmdir
func CmdSTM() int {
	if OptionsVar.Server == "" {
		log.Fatal("Server must be specified: --server\n")
		return 1
	}
	if OptionsVar.Stmdir == "" {
		log.Fatal("Missing parameter: --stmdir\n")
		return 1
	}
	if !isDir(OptionsVar.Stmdir) {
		log.Fatalf("stmdir does not exist or is no directory: %s\n", OptionsVar.Stmdir)
		return 1
	}
	err := listSTM(OptionsVar.Stmdir) // Todo: Test if dir exists
	if err != nil {
		log.Errorf("STM Process errors: %s\n", err)
		return 1
	}
	return 0
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:21,代碼來源:stm.go

示例14: CmdGenTempKey

// CmdGenTempKey generates a temporary key for a given private key
func CmdGenTempKey() int {
	var privkey message.Curve25519Key
	privkeystr := selectPrivKey(OptionsVar.Privkey, GlobalConfigVar.PrivateKey, "tty")
	if privkeystr == "" {
		log.Fatal("No private key given (-privkey)")
		return 1
	}
	copy(privkey[:], utils.B58decode(privkeystr))
	pubkey := message.GenPubKey(&privkey)
	privkeytemp, err := message.GenRandomKey()
	if err != nil {
		log.Errorf("Key generation error:%s\n", err)
		return 1
	}
	pubkeytemp := message.GenPubKey(privkeytemp)
	log.Dataf("STATUS (PrivateKey):\t%s_%s\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Dataf("STATUS (PublicKey):\t%s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	log.Printf("PRIVATE key: %s_%s\n\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Printf("Public key: %s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	return 0
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:22,代碼來源:genkey.go

示例15: runCommands

func runCommands() (retval int) {
	log.SetMinLevel(log.LevelPrint)
	if options.Appdata {
		log.SetMinLevel(log.LevelData)
	}
	if options.Verbose {
		log.SetMinLevel(log.LevelDebug)
	}
	if options.KEYVERB {
		log.SetMinLevel(log.LevelSecret)
	}
	usercfgfile := client.UserConfigFile()
	if options.Configfile != "" || usercfgfile != "" {
		configFile := usercfgfile
		if options.Configfile != "" {
			configFile = options.Configfile
		}
		globalconfigT, err := client.LoadConfigFile(configFile)
		if err == nil {
			globalconfig = globalconfigT
		} else {
			log.Errorf("Config file failed to load: %s\n", err)
		}
	}
	for k, v := range commands {
		if *v {
			if callFunc[k] != nil {
				client.OptionsVar = options
				client.GlobalConfigVar = globalconfig
				retval = callFunc[k]()
			} else {
				log.Fatal("Command not implemented")
				return 100
			}
			log.Sync()
			break
		}
	}
	return
}
開發者ID:RoPe93,項目名稱:repbin,代碼行數:40,代碼來源:repclient.go


注:本文中的github.com/repbin/repbin/deferconsole.Errorf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。