• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang go-appkit.File类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/app-kit/go-appkit.File的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了File类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Delete

func (h *FileService) Delete(f kit.File, u kit.User) apperror.Error {
	// Delete file from backend.
	if f.GetBackendName() != "" && f.GetBackendId() != "" {
		backend := h.Backend(f.GetBackendName())
		if backend == nil {
			h.Registry().Logger().Errorf("Deleting file %v in backend %v, which is unconfigured", f.GetId(), f.GetBackendName())
		} else {
			if err := backend.DeleteFile(f); err != nil {
				return err
			}
		}
	}

	return h.resource.Delete(f, u)
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:15,代码来源:service.go


示例3: 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


示例4: SetParentFile

func (f *FileIntId) SetParentFile(file kit.File) {
	f.ParentFile = file.(*FileIntId)
	f.ParentFileId = file.GetId().(uint64)
}
开发者ID:app-kit,项目名称:go-appkit,代码行数:4,代码来源:models.go


示例5: 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


示例6: 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


示例7: 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


示例8: 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


示例9: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang go-appkit.Model类代码示例发布时间:2022-05-24
下一篇:
Golang go-appkit.NewErrorResponse函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap