本文整理汇总了Golang中github.com/jcelliott/lumber.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getObject
func getObject(rw http.ResponseWriter, req *http.Request) {
obj, err := models.GetObject(userId(req), userKey(req), bucketId(req), objectId(req))
if err != nil {
lumber.Error("Get Object: Get :%s", err.Error())
rw.WriteHeader(422)
return
}
if obj.Size == 0 {
lumber.Info("object size is 0", obj.Size)
rw.WriteHeader(422)
rw.Write([]byte("incomplete file"))
return
}
rc, err := obj.ReadCloser()
if err != nil {
lumber.Error("Get Object: Get ReadCloser :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
defer rc.Close()
rw.Header().Set("Content-Type", "application/octet-stream")
_, err = io.Copy(rw, rc)
if err != nil {
lumber.Error("Get Object: Copy :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
}
示例2: deleteObject
func deleteObject(rw http.ResponseWriter, req *http.Request) {
obj, err := models.GetObject(userId(req), userKey(req), bucketId(req), objectId(req))
if err != nil {
lumber.Error("Delete Object: Get :%s", err.Error())
rw.WriteHeader(http.StatusAccepted)
return
}
err = obj.Remove()
if err != nil && !strings.Contains(err.Error(), "no such file") {
lumber.Error("Delete Object: Remove :%s", err.Error())
// if i cant remove it im assuming it was already gone
// we will probably need to check on this sometime soon
// to confirm we are not leaving cruft
if obj.Size != 0 {
// if the object size is 0 dont worry about a failed remove
// chances are the object didnt have any data in it.
rw.WriteHeader(http.StatusInternalServerError)
return
}
}
err = models.DeleteObject(userId(req), userKey(req), obj.BucketID, obj.ID)
if err != nil {
lumber.Error("Delete Object: Delete :%s", err.Error())
rw.WriteHeader(http.StatusAccepted)
return
}
rw.WriteHeader(http.StatusAccepted)
}
示例3: setObjectPublic
func setObjectPublic(rw http.ResponseWriter, req *http.Request) {
obj, err := models.GetObject(userId(req), userKey(req), bucketId(req), objectId(req))
if err != nil {
lumber.Error("SetObjectPublic: Get :%s", err.Error())
rw.WriteHeader(http.StatusNotFound)
return
}
obj.Public = true
err = models.SaveObject(obj)
if err != nil {
lumber.Error("SetObjectPublic: Save :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
bytes, err := json.Marshal(obj)
if err != nil {
lumber.Error("SetObjectPublic: Json Marshal :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(bytes)
}
示例4: adminAccess
func adminAccess(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
userId := req.Header.Get("Userid")
userKey := req.Header.Get("Key")
if userId == "" || userKey == "" {
lumber.Error("no userid or key given")
rw.WriteHeader(http.StatusNotFound)
return
}
// get a user and return it
user, err := models.GetUser(userId)
if err != nil {
lumber.Error("get user: %s", err.Error())
}
if user == nil || user.Key != userKey || user.Admin == false {
lumber.Error("User not authorized %+v", user)
rw.WriteHeader(http.StatusNotFound)
return
}
fn(rw, req)
}
}
示例5: main
func main() {
setLogLevel()
runtime.GOMAXPROCS(runtime.NumCPU())
var be models.Storage
switch selectedBackend {
case "local":
be = backends.NewLocalStorage(backendCredentials)
default:
be = backends.NewLocalStorage(backendCredentials)
}
err := models.Initialize(dbCredentials, be)
if err != nil {
panic(err)
}
models.CleanEmptyObjects()
err = api.Start(port)
lumber.Error(err.Error())
}
示例6: startHoarder
func startHoarder(ccmd *cobra.Command, args []string) error {
// convert the log level
logLvl := lumber.LvlInt(viper.GetString("log-level"))
// configure the logger
lumber.Prefix("[hoader]")
lumber.Level(logLvl)
// enable/start garbage collection if age config was changed
if ccmd.Flag("clean-after").Changed {
lumber.Debug("Starting garbage collector (data older than %vs)...\n", ccmd.Flag("clean-after").Value)
// start garbage collector
go collector.Start()
}
// set, and initialize, the backend driver
if err := backends.Initialize(); err != nil {
lumber.Error("Failed to initialize backend - %v", err)
return err
}
// start the API
if err := api.Start(); err != nil {
lumber.Fatal("Failed to start API: ", err.Error())
return err
}
return nil
}
示例7: Send
func (c *Client) Send() {
for msg := range c.messages {
log.Trace("Sending message: %s", msg)
if err := websocket.Message.Send(c.ws, msg); err != nil {
log.Error("Error sending message: %s", err)
}
}
}
示例8: listBuckets
func listBuckets(rw http.ResponseWriter, req *http.Request) {
bucks, err := models.ListBuckets(userId(req), userKey(req))
if err != nil {
lumber.Error("List Bucket :%s", err.Error())
rw.WriteHeader(http.StatusNotFound)
return
}
b, err := json.Marshal(bucks)
if err != nil {
lumber.Error("List Bucket: Parse Json :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(b)
}
示例9: listObjects
func listObjects(rw http.ResponseWriter, req *http.Request) {
objs, err := models.ListObjects(userId(req), userKey(req), bucketId(req))
if err != nil {
lumber.Error("List Object: Get :%s", err.Error())
rw.WriteHeader(422)
return
}
b, err := json.Marshal(objs)
if err != nil {
lumber.Error("List Object: Json Marshal :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(b)
}
示例10: PublishAfter
// PublishAfter sends a message after [delay]
func (p *Proxy) PublishAfter(tags []string, data string, delay time.Duration) {
go func() {
<-time.After(delay)
if err := publish(p.id, tags, data); err != nil {
// log this error and continue
lumber.Error("Proxy failed to PublishAfter - %v", err)
}
}()
}
示例11: listUsers
func listUsers(rw http.ResponseWriter, req *http.Request) {
users, err := models.ListUsers()
if err != nil {
lumber.Error("List User: Get :%s", err.Error())
rw.WriteHeader(http.StatusNotFound)
return
}
b, err := json.Marshal(users)
if err != nil {
lumber.Error("List User: Json Marshel :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(b)
}
示例12: parseBody
// parseBody parses the json body into v
func parseBody(req *http.Request, v interface{}) error {
// read the body
b, err := ioutil.ReadAll(req.Body)
if err != nil {
lumber.Error(err.Error())
return BodyReadFail
}
defer req.Body.Close()
// parse body and store in v
err = json.Unmarshal(b, v)
if err != nil {
lumber.Error(err.Error())
return BadJson
}
return nil
}
示例13: handlePrefix
func (t *Server) handlePrefix(id string, msg PrefixMsg) {
log.Trace("Handling prefix message")
if _, ok := t.prefixes[id]; !ok {
t.prefixes[id] = make(PrefixMap)
}
if err := t.prefixes[id].RegisterPrefix(msg.Prefix, msg.URI); err != nil {
log.Error("Error registering prefix: %s", err)
}
log.Debug("Client %s registered prefix '%s' for URI: %s", id, msg.Prefix, msg.URI)
}
示例14: deleteBucket
func deleteBucket(rw http.ResponseWriter, req *http.Request) {
err := models.DeleteBucket(userId(req), userKey(req), bucketId(req))
if err != nil {
lumber.Error("Delete Bucket :%s", err.Error())
rw.WriteHeader(http.StatusNotAcceptable)
return
}
rw.WriteHeader(http.StatusAccepted)
}
示例15: runLoop
// runLoop handles communication from the server
func (relay *Relay) runLoop(reader *bufio.Reader) {
for {
// when implementing relay, set `lumber.Level(lumber.LvlInt("TRACE"))` in client to view logs
line, err := reader.ReadString('\n')
if err != nil {
lumber.Error("[PULSE :: RELAY] Disconnected from host %v!", relay.hostAddr)
// retry indefinitely
for {
if reader, err = relay.establishConnection(); err == nil {
lumber.Info("[PULSE :: RELAY] Reconnected to host %v!", relay.hostAddr)
break
}
lumber.Debug("[PULSE :: RELAY] Reconnecting to host %v... Fail!", relay.hostAddr)
<-time.After(5 * time.Second)
}
// we won't have anything in 'line' so continue
continue
}
line = strings.TrimSuffix(line, "\n")
split := strings.SplitN(line, " ", 2)
cmd := split[0]
switch cmd {
case "ok":
lumber.Trace("[PULSE :: RELAY] OK: %v", split)
// just an ack
case "get":
lumber.Trace("[PULSE :: RELAY] GET: %v", split)
if len(split) != 2 {
continue
}
stats := strings.Split(split[1], ",")
results := make([]string, 0)
for _, stat := range stats {
tagCollector, ok := relay.collectors[stat]
if !ok {
continue
}
for name, value := range tagCollector.collector.Collect() {
formatted := strconv.FormatFloat(value, 'f', 4, 64)
if name == "" {
name = stat
}
results = append(results, fmt.Sprintf("%s-%s:%s", stat, name, formatted))
}
}
response := fmt.Sprintf("got %s\n", strings.Join(results, ","))
relay.conn.Write([]byte(response))
default:
lumber.Trace("[PULSE :: RELAY] BAD: %v", split)
relay.conn.Write([]byte("unknown command\n"))
}
}
}