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


Golang Logger.Errorln方法代碼示例

本文整理匯總了Golang中github.com/Sirupsen/logrus.Logger.Errorln方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Errorln方法的具體用法?Golang Logger.Errorln怎麽用?Golang Logger.Errorln使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/Sirupsen/logrus.Logger的用法示例。


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

示例1: PutObjectInfoHandler

func PutObjectInfoHandler(ctx *macaron.Context, log *logrus.Logger) (int, []byte) {
	data, _ := ctx.Req.Body().Bytes()
	fmt.Println("data= %v", data)
	reqBody := make(map[string]interface{})
	json.Unmarshal(data, &reqBody)
	fragments := reqBody["fragments"].([]interface{})

	if len(fragments) == 0 {
		return http.StatusBadRequest, []byte("Invalid Parameters")
	}

	dbInstance := db.SQLDB.GetDB().(*gorm.DB)

	object_id := reqBody["object_id"].(string)
	object_key := reqBody["object_key"].(string)
	md5_key := reqBody["md5_key"].(string)

	// Remove the old relations
	if result := dbInstance.Exec("DELETE FROM object WHERE object_id='" + object_id + "'"); result.Error != nil {
		log.Errorln(result.Error.Error())
		return http.StatusInternalServerError, []byte("Internal Server Error")
	}

	// Save ObjectMeta
	insertOrUpdateSQL := fmt.Sprintf("REPLACE INTO object_meta(id, object_key, md5_key) VALUES(%q, %q, %q)", object_id, object_key, md5_key)
	if result := dbInstance.Exec(insertOrUpdateSQL); result.Error != nil {
		log.Errorln(result.Error.Error())
		return http.StatusInternalServerError, []byte("Internal Server Error")
	}

	// Save fragments and the relation
	insertFragmentsSQL := "INSERT INTO fragment(id, `index`, start, end, group_id, file_id, is_last, mod_time) VALUES "
	insertRelationsSQL := "REPLACE INTO object(object_id, fragment_id) VALUES "

	for index := range fragments {
		fmt.Println(fragments)
		f := fragments[index].(map[string]interface{})

		fragmentID := utils.MD5ID()
		index := int(f["index"].(float64))
		start := int64(f["start"].(float64))
		end := int64(f["end"].(float64))
		group_id := f["group_id"].(string)
		file_id := f["file_id"].(string)
		is_last := f["is_last"].(bool)

		// modTimeStr := f["mod_time"].(string)
		// t, err := time.Parse("2006-01-02T15:04:05Z", modTimeStr)
		// if err != nil {
		// 	log.Errorln(err.Error())
		// 	return http.StatusBadRequest, []byte("Invalid Parameters")
		// }
		timenow := time.Now()
		mod_time := timenow.Format("2006-01-02 15:04:05")

		insertFragmentSQL := fmt.Sprintf("(%q,%d,%d,%d,%q,%q,%t,%q),", fragmentID, index, start, end, group_id, file_id, is_last, mod_time)
		insertFragmentsSQL += insertFragmentSQL

		insertRelationSQL := fmt.Sprintf("(%q,%q),", reqBody["object_id"], fragmentID)
		insertRelationsSQL += insertRelationSQL
	}

	insertFragmentsSQL = insertFragmentsSQL[:len(insertFragmentsSQL)-1]
	if result := db.SQLDB.GetDB().(*gorm.DB).Exec(insertFragmentsSQL); result.Error != nil {
		log.Errorln(result.Error.Error())
		return http.StatusInternalServerError, []byte("Internal Server Error")
	}

	insertRelationsSQL = insertRelationsSQL[:len(insertRelationsSQL)-1]
	if result := db.SQLDB.GetDB().(*gorm.DB).Exec(insertRelationsSQL); result.Error != nil {
		log.Errorln(result.Error.Error())
		return http.StatusInternalServerError, []byte("Internal Server Error")
	}

	return http.StatusOK, nil
}
開發者ID:containerops,項目名稱:arkor,代碼行數:76,代碼來源:object.go

示例2: GetObjectInfoHandler

func GetObjectInfoHandler(ctx *macaron.Context, log *logrus.Logger) (int, []byte) {
	objectID := ctx.Params(":object")

	sql := fmt.Sprintf(
		"SELECT object.object_id, object.fragment_id, object_key, md5_key, `index`, start, end, group_id, file_id, is_last, mod_time FROM object, object_meta, fragment WHERE object_meta.id=%q AND object.object_id=%q  AND fragment.id=object.fragment_id",
		objectID, objectID)

	dbInstace := db.SQLDB.GetDB().(*gorm.DB)

	rows, err := dbInstace.Raw(sql).Rows()
	if err != nil {
		return http.StatusInternalServerError, []byte("Internal Server Error")
	}

	defer rows.Close()

	object := make(map[string]interface{})
	fragments := []interface{}{}
	for rows.Next() {
		var object_id string
		var fragment_id string
		var object_key string
		var md5_key string
		var index int
		var start int64
		var end int64
		var group_id string
		var file_id string
		var is_last bool
		var mod_time string

		rows.Scan(&object_id, &fragment_id, &object_key, &md5_key, &index, &start, &end, &group_id, &file_id, &is_last, &mod_time)

		object["object_id"] = object_id
		object["md5_key"] = md5_key
		object["object_key"] = object_key

		fragment := make(map[string]interface{})
		fragment["index"] = index
		fragment["start"] = start
		fragment["end"] = end
		fragment["group_id"] = group_id
		fragment["file_id"] = file_id
		fragment["is_last"] = is_last
		if mod_time == "" {
			mod_time = time.Now().Format("2006-01-02T15:04:05Z07:00")
		}
		fragment["mod_time"] = mod_time

		fragments = append(fragments, fragment)
	}
	object["fragments"] = fragments

	result, err := json.Marshal(object)

	if err != nil {
		log.Errorln(err.Error())
		return http.StatusInternalServerError, []byte("Internal Server Error")

	}
	ctx.Resp.Header().Set("Content-Type", "application/json")
	return http.StatusOK, result
}
開發者ID:containerops,項目名稱:arkor,代碼行數:63,代碼來源:object.go


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