Some work on unfying actions on different sources.
This commit is contained in:
37
post/main.go
Normal file
37
post/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package post
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type UnifiedPost interface {
|
||||
ID() string
|
||||
Name() string
|
||||
Author() string
|
||||
Comment() string
|
||||
Tags() []string
|
||||
Files() []string
|
||||
URL() string
|
||||
Stringer() string
|
||||
Type() string
|
||||
}
|
||||
|
||||
// WriteAttributes writes info from post to file's metadata
|
||||
func WriteAttributes(filename string, post UnifiedPost) (err error) {
|
||||
var tags string
|
||||
for _, tag := range post.Tags() {
|
||||
tags = fmt.Sprintf("%s,%s", tags, tag)
|
||||
}
|
||||
err = syscall.Setxattr(filename, "user.xdg.tags", []byte(tags), 0)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
||||
return
|
||||
}
|
||||
err = syscall.Setxattr(filename, "user.xdg.comment", []byte(post.Comment()), 0)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user