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


Golang File.GetBucket方法代碼示例

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


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

示例1: Writer

func (fs Fs) Writer(f kit.File, create bool) (string, io.WriteCloser, apperror.Error) {
	id := f.GetBackendId()
	if create {
		id = f.GetFullName()
	}
	return fs.WriterById(f.GetBucket(), id, create)
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:7,代碼來源:fs.go

示例2: getImageReader

func (r *FilesResource) getImageReader(registry kit.Registry, tmpDir string, file kit.File, width, height int64, filters []string, ip string) (reader kit.ReadSeekerCloser, size int64, err apperror.Error) {
	if width == 0 && height == 0 && len(filters) == 0 {
		reader, err = file.Reader()
		return
	}

	// Dimensions specified.
	// Check if the thumbnail was already created.
	// If so, serve it. Otherwise, create it first.

	if (width == 0 || height == 0) && (file.GetWidth() == 0 || file.GetHeight() == 0) {
		err = &apperror.Err{
			Code:    "image_dimensions_not_determined",
			Message: fmt.Sprintf("The file with id %v does not have width/height", file.GetId()),
		}
		return
	}

	if width < 0 || height < 0 {
		err = apperror.New("invalid_dimensions")
		return
	}

	// If either height or width is 0, determine proper values to presserve aspect ratio.
	if width == 0 {
		ratio := float64(file.GetWidth()) / float64(file.GetHeight())
		width = int64(float64(height) * ratio)
	} else if height == 0 {
		ratio := float64(file.GetHeight()) / float64(file.GetWidth())
		height = int64(float64(width) * ratio)
	}

	maxWidth := registry.Config().UInt("files.thumbGenerator.maxWidth", 2000)
	maxHeight := registry.Config().UInt("files.thumbGenerator.maxHeight", 2000)

	if width > int64(maxWidth) || height > int64(maxHeight) {
		err = &apperror.Err{
			Code:    "dimensions_exceed_maximum_limits",
			Message: "The specified dimensions exceed the maximum limits",
		}
		return
	}

	thumbId := fmt.Sprintf("%v_%v_%v_%v_%v_%v.%v",
		file.GetId(),
		file.GetBucket(),
		file.GetName(),
		strconv.FormatInt(width, 10),
		strconv.FormatInt(height, 10),
		strings.Replace(strings.Join(filters, "_"), ":", "_", -1),
		"jpeg")

	if ok, _ := file.GetBackend().HasFileById("thumbs", thumbId); !ok {
		var channel chan bool
		channel, err = r.thumbnailRateLimiter.Start(ip)
		if err != nil {
			return
		}
		if channel != nil {
			<-channel
		}

		// Thumb does not exist yet, so create it.
		reader, err = file.Reader()
		if err != nil {
			return
		}
		defer reader.Close()

		img, _, err2 := image.Decode(reader)
		if err2 != nil {
			err = apperror.Wrap(err2, "image_decode_error")
			return
		}

		var giftFilters []gift.Filter

		if !(height == 0 && width == 0) {
			giftFilters = append(giftFilters, gift.ResizeToFill(int(width), int(height), gift.LanczosResampling, gift.CenterAnchor))
		}

		for _, filter := range filters {
			if filter == "" {
				continue
			}

			parts := strings.Split(filter, ":")

			if len(parts) > 1 {
				filter = parts[0]
			}

			switch filter {
			case "sepia":
				n := float32(100)

				if len(parts) == 2 {
					x, err2 := strconv.ParseFloat(parts[1], 64)
					if err2 == nil {
						n = float32(x)
//.........這裏部分代碼省略.........
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:101,代碼來源:resource.go

示例3: Reader

func (fs Fs) Reader(f kit.File) (kit.ReadSeekerCloser, apperror.Error) {
	return fs.ReaderById(f.GetBucket(), f.GetBackendId())
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:3,代碼來源:fs.go

示例4: DeleteFile

func (fs Fs) DeleteFile(f kit.File) apperror.Error {
	return fs.DeleteFileById(f.GetBucket(), f.GetBackendId())
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:3,代碼來源:fs.go

示例5: FileSize

func (fs Fs) FileSize(file kit.File) (int64, apperror.Error) {
	return fs.FileSizeById(file.GetBucket(), file.GetBackendId())
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:3,代碼來源:fs.go

示例6: HasFile

func (fs Fs) HasFile(f kit.File) (bool, apperror.Error) {
	return fs.HasFileById(f.GetBucket(), f.GetBackendId())
}
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:3,代碼來源:fs.go

示例7: BuildFile

func (h FileService) BuildFile(file kit.File, user kit.User, deleteDir, deleteFile bool) apperror.Error {
	if h.DefaultBackend == nil {
		return &apperror.Err{
			Code:    "no_default_backend",
			Message: "Cant build a file without a default backend.",
		}
	}

	filePath := file.GetTmpPath()
	if filePath == "" {
		return &apperror.Err{
			Code:    "no_tmp_path",
			Message: "You must set TmpPath on a file before building it.",
			Public:  true,
		}
	}

	if file.GetBackendName() == "" {
		file.SetBackendName(h.DefaultBackend().Name())
	}

	backend := h.Backend(file.GetBackendName())
	if backend == nil {
		return &apperror.Err{
			Code:    "unknown_backend",
			Message: fmt.Sprintf("The backend %v does not exist", file.GetBackendName()),
		}
	}

	file.SetBackend(backend)

	if file.GetBucket() == "" {
		return &apperror.Err{
			Code:    "missing_bucket",
			Message: "Bucket must be set on the file",
		}
	}

	stat, err := os.Stat(filePath)
	if err != nil {
		if err == os.ErrNotExist {
			return &apperror.Err{
				Code:    "file_not_found",
				Message: fmt.Sprintf("File %v does not exist", filePath),
			}
		}

		return apperror.Wrap(err, "stat_error",
			fmt.Sprintf("Could not get file stats for file at %v: %v", filePath, err))
	}

	if stat.IsDir() {
		return apperror.New("path_is_directory")
	}

	// Build the hash.
	hash, err2 := utils.BuildFileMD5Hash(filePath)
	if err2 != nil {
		return err2
	}

	file.SetHash(hash)

	pathParts := strings.Split(filePath, string(os.PathSeparator))
	fullName := pathParts[len(pathParts)-1]
	nameParts := strings.Split(fullName, ".")

	// Determine extension.
	extension := ""
	if len(nameParts) > 1 {
		extension = nameParts[len(nameParts)-1]
	}

	file.SetFullName(fullName)
	file.SetSize(stat.Size())

	// Determine mime type.
	mimeType := GetMimeType(filePath)
	if mimeType == "" {
		mimeType = mime.TypeByExtension("." + extension)
	}
	file.SetMime(mimeType)

	if strings.HasPrefix(mimeType, "image") {
		file.SetIsImage(true)
		file.SetMediaType(MEDIA_TYPE_IMAGE)

		// Determine image info.
		imageInfo, err := GetImageInfo(filePath)
		if imageInfo != nil {
			file.SetWidth(int(imageInfo.Width))
			file.SetHeight(int(imageInfo.Height))
		} else {
			h.Registry().Logger().Warningf("Could not determine image info: %v", err)
		}
	}

	if strings.HasPrefix(mimeType, "video") {
		file.SetMediaType(MEDIA_TYPE_VIdEO)
	}
//.........這裏部分代碼省略.........
開發者ID:app-kit,項目名稱:go-appkit,代碼行數:101,代碼來源:service.go


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