本文整理汇总了Golang中github.com/jcelliott/lumber.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:31,代码来源:objects.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:31,代码来源:objects.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:25,代码来源:objects.go
示例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)
}
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:25,代码来源:api.go
示例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())
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:26,代码来源:main.go
示例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
}
开发者ID:nanopack,项目名称:hoarder,代码行数:30,代码来源:commands.go
示例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)
}
}
}
开发者ID:hfeeki,项目名称:turnpike,代码行数:8,代码来源:client.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:18,代码来源:buckets.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:18,代码来源:objects.go
示例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)
}
}()
}
开发者ID:nanopack,项目名称:mist,代码行数:10,代码来源:proxy.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:18,代码来源:users.go
示例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
}
开发者ID:nanopack,项目名称:pulse,代码行数:20,代码来源:api.go
示例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)
}
开发者ID:hfeeki,项目名称:turnpike,代码行数:10,代码来源:server.go
示例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)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:10,代码来源:buckets.go
示例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"))
}
}
}
开发者ID:nanopack,项目名称:pulse,代码行数:56,代码来源:relay.go
示例16: PublishAfter
// PublishAfter publishes to ALL subscribers. Usefull in client applications
// who reuse the publish connection for subscribing
func PublishAfter(tags []string, data string, delay time.Duration) error {
go func() {
<-time.After(delay)
if err := Publish(tags, data); err != nil {
// log this error and continue?
lumber.Error("Failed to PublishAfter - %v", err)
}
}()
return nil
}
开发者ID:nanopack,项目名称:mist,代码行数:13,代码来源:mist.go
示例17: deleteUser
func deleteUser(rw http.ResponseWriter, req *http.Request) {
id := req.URL.Query().Get(":id")
err := models.DeleteUser(id)
if err != nil {
lumber.Error("Delete User: Delete :%s", err.Error())
rw.WriteHeader(http.StatusNotAcceptable)
return
}
rw.WriteHeader(http.StatusAccepted)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:11,代码来源:users.go
示例18: createBucket
func createBucket(rw http.ResponseWriter, req *http.Request) {
buck, err := models.CreateBucket(userId(req), userKey(req), bucketId(req))
if err != nil {
lumber.Error("New Bucket :%s", err.Error())
rw.WriteHeader(422)
return
}
b, _ := json.Marshal(buck)
rw.WriteHeader(http.StatusCreated)
rw.Header().Set("Content-Type", "application/json")
rw.Write(b)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:13,代码来源:buckets.go
示例19: createUser
func createUser(rw http.ResponseWriter, req *http.Request) {
s := sizeLimit(req)
newUser, err := models.CreateUser(s)
if err != nil {
lumber.Error("Create User: Create :%s", err.Error())
rw.WriteHeader(422)
return
}
b, _ := json.Marshal(newUser)
rw.WriteHeader(http.StatusCreated)
rw.Header().Set("Content-Type", "application/json")
rw.Write(b)
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:14,代码来源:users.go
示例20: getObjectInfo
func getObjectInfo(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 Info: Get :%s", err.Error())
rw.WriteHeader(http.StatusNotFound)
return
}
rw.Header().Set("Object-Alias", obj.Alias)
rw.Header().Set("Object-Size", strconv.FormatInt(obj.Size, 10))
rw.Header().Set("Object-Checksum", obj.CheckSum)
if req.Method == "GET" {
bytes, err := json.Marshal(obj)
if err != nil {
lumber.Error("Get Object Info: Json Marshal :%s", err.Error())
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(bytes)
}
}
开发者ID:nanobox-apps,项目名称:sample-go,代码行数:24,代码来源:objects.go
注:本文中的github.com/jcelliott/lumber.Error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论