本文整理匯總了Golang中github.com/app-kit/go-appkit.File.GetName方法的典型用法代碼示例。如果您正苦於以下問題:Golang File.GetName方法的具體用法?Golang File.GetName怎麽用?Golang File.GetName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/app-kit/go-appkit.File
的用法示例。
在下文中一共展示了File.GetName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
//.........這裏部分代碼省略.........