本文整理汇总了Golang中github.com/stacktic/dropbox.Dropbox类的典型用法代码示例。如果您正苦于以下问题:Golang Dropbox类的具体用法?Golang Dropbox怎么用?Golang Dropbox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dropbox类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
err := rpio.Open()
if err != nil {
fmt.Println("rpio.Open()")
fmt.Println(err)
}
// Unmap gpio memory when done
defer rpio.Close()
toggleLight(9)
var db *dropbox.Dropbox
db = dropbox.NewDropbox()
db.SetAppInfo(clientid, clientsecret)
db.SetAccessToken(token)
toggleLight(10)
shoot(db)
toggleLight(11)
}
开发者ID:overeemm,项目名称:gocam,代码行数:25,代码来源:cam.go
示例2: New
// New creates a client to connect to Dropbox.
func New(key, secret, token string) (db *Dropbox, err error) {
if key == "" {
err = errors.New("empty key")
return
}
if secret == "" {
err = errors.New("empty secret")
return
}
if token == "" {
err = errors.New("empty token")
return
}
var (
client *dropbox.Dropbox
)
client = dropbox.NewDropbox()
client.SetAppInfo(key, secret)
client.SetAccessToken(token)
db = &Dropbox{
client: client,
cwd: "/",
}
return
}
开发者ID:noisypixy,项目名称:go-dropboxfs,代码行数:30,代码来源:dropbox.go
示例3: shoot
func shoot(db *dropbox.Dropbox) {
cmd := exec.Command("raspistill", "-n", "-o", "-")
out, err := cmd.StdoutPipe()
if err != nil {
fmt.Println("cmd.StdoutPipe()")
fmt.Println(err)
}
err = cmd.Start()
if err != nil {
fmt.Println("cmd.Start()")
fmt.Println(err)
}
data, err := ioutil.ReadAll(out)
if err != nil {
fmt.Println("ioutil.ReadAll(out)")
fmt.Println(err)
}
cmd.Wait()
now := time.Now().Format("2006-01-02 150405")
len := int64(len(data))
bytes := NopReadCloser(bytes.NewReader(data))
_, err = db.FilesPut(bytes, len, fmt.Sprintf("%s.jpg", now), true, "")
if err != nil {
fmt.Println("db.FilesPut(...)")
fmt.Println(err)
}
}
开发者ID:overeemm,项目名称:gocam,代码行数:32,代码来源:cam.go
示例4: get
/*
Actually get a list of directories or files from the dropbox connection
*/
func get(cache *cache.Cache, db *dropbox.Dropbox, path string, directories bool) []dropbox.Entry {
// Use caching to reduce calls to the Dropbox API
var cache_descriptor string
if directories {
cache_descriptor = "dirs:"
} else {
cache_descriptor = "files:"
}
s := []string{}
s = append(s, cache_descriptor)
s = append(s, path)
cache_path := strings.Join(s, "")
data, found := cache.Get(cache_path)
if found {
if cached_paths, ok := data.([]dropbox.Entry); ok {
return (cached_paths)
} else {
log.Println("Error: Unable to retrieve from cache")
}
}
entry, err := db.Metadata(path, true, false, "", "", 500)
if err != nil {
log.Println(err)
return []dropbox.Entry{}
}
paths := make([]dropbox.Entry, 0)
for i := 0; i < len(entry.Contents); i++ {
entry := entry.Contents[i]
if directories {
if entry.IsDir {
paths = append(paths, entry)
}
} else {
if !entry.IsDir {
include := true
for _, lookup := range do_not_include {
if strings.Contains(entry.Path, lookup) {
include = false
}
}
if include {
paths = append(paths, entry)
}
}
}
}
cache.Set(cache_path, paths, 0)
return paths
}
开发者ID:warricksothr,项目名称:RustBuild-Linker,代码行数:54,代码来源:rustbuild-linker.go
示例5: loadDropboxFile
/* Retrieves files from the users Dropbox. Returns a byte
* array of the files contents. */
func loadDropboxFile(path string, db *dropbox.Dropbox) ([]byte, error) {
closer, _, err := db.Download(path, "", 0)
if err != nil {
fmt.Printf("Error loading dropbox file: %v\n", err)
return nil, err
}
file, err := ioutil.ReadAll(closer)
return file, err
}
开发者ID:ckagiri,项目名称:YNAWB,代码行数:18,代码来源:main.go
示例6: main
func main() {
configFile, err := ioutil.ReadFile("config.json")
if err != nil {
panic("Error opening config file: " + err.Error())
}
var c config
err = json.Unmarshal(configFile, &c)
if err != nil {
panic(err)
}
var db *dropbox.Dropbox
// 1. Create a new dropbox object.
db = dropbox.NewDropbox()
// 2. Provide your clientid and clientsecret (see prerequisite).
db.SetAppInfo(c.Clientid, c.Clientsecret)
// 3. Provide the user token.
db.SetAccessToken(c.Token)
fmt.Println(c.DropboxPath)
err = db.DownloadToFile(c.DropboxPath, c.Destination, "")
if err != nil {
panic(err)
}
}
开发者ID:jahands,项目名称:gitworkflowy,代码行数:28,代码来源:main.go
示例7: handler
func handler(w http.ResponseWriter, r *http.Request) {
var err error
var db *dropbox.Dropbox
var input io.ReadCloser
var length int64
var ok bool
var cachedItem interface{}
var s string
if r.URL.Path[1:] == "favicon.ico" {
return
}
cachedItem, ok = Lru.Get(r.URL.Path[1:])
if ok {
item := cachedItem.(cacheItem)
s = item.Value
length = item.Length
} else {
var clientid, clientsecret string
var token string
clientid = os.Getenv("CLIENTID")
clientsecret = os.Getenv("CLIENTSECRET")
token = os.Getenv("TOKEN")
// 1. Create a new dropbox object.
db = dropbox.NewDropbox()
// 2. Provide your clientid and clientsecret (see prerequisite).
db.SetAppInfo(clientid, clientsecret)
// 3. Provide the user token.
db.SetAccessToken(token)
// 4. Send your commands.
// In this example, you will create a new folder named "demo".
if input, length, _, err = db.Thumbnails("/"+r.URL.Path[2:], "jpeg", r.URL.Path[1:2]); err != nil {
fmt.Printf("Error: %s Url: %s Size: \n", err, r.URL.Path[2:], r.URL.Path[1:2])
} else {
//fmt.Printf("Error %s\n", input)
buf := new(bytes.Buffer)
buf.ReadFrom(input)
s = buf.String()
Lru.Add(r.URL.Path[1:], cacheItem{Value: s, Length: length})
}
}
w.Header().Set("Content-Length", strconv.FormatInt(length, 10))
fmt.Fprintf(w, "%s", s)
}
开发者ID:shaunmza,项目名称:dbthumbnails,代码行数:56,代码来源:dbthumbnails.go
示例8: get_link
/*
Returns a shared link to dropbox file
*/
func get_link(cache *cache.Cache, db *dropbox.Dropbox, path string) string {
// Use caching to reduce calls to the Dropbox API
cache_path := strings.Join([]string{"link", path}, ":")
data, found := cache.Get(cache_path)
if found {
if cached, ok := data.(string); ok {
return cached
} else {
log.Println("Error: Unable to retrieve from cache")
}
}
link, err := db.Shares(path, false)
if err != nil {
log.Println(err)
return ""
}
cache.Set(cache_path, link.URL, 0)
return link.URL
}
开发者ID:warricksothr,项目名称:RustBuild-Linker,代码行数:24,代码来源:rustbuild-linker.go
示例9: WriteFile
func WriteFile(config *DropboxConfig, file string, content string) error {
var db *dropbox.Dropbox
db = dropbox.NewDropbox()
db.SetAppInfo(config.AppKey, config.AppSecret)
db.SetAccessToken(config.Token)
in := ioutil.NopCloser(bytes.NewBufferString(content))
_, err := db.UploadByChunk(in, 1024, file, true, "")
return err
}
开发者ID:sdemingo,项目名称:worgenda,代码行数:11,代码来源:dropbox.go
示例10: ReadFile
func ReadFile(config *DropboxConfig, file string) (string, error) {
var err error
var db *dropbox.Dropbox
var s string
db = dropbox.NewDropbox()
db.SetAppInfo(config.AppKey, config.AppSecret)
db.SetAccessToken(config.Token)
rd, _, err := db.Download(file, "", 0)
if err != nil {
return s, err
}
buf := new(bytes.Buffer)
buf.ReadFrom(rd)
s = buf.String()
return s, nil
}
开发者ID:sdemingo,项目名称:worgenda,代码行数:21,代码来源:dropbox.go
示例11: handleOriginalFile
func handleOriginalFile(w http.ResponseWriter, r *http.Request) {
var err error
var db *dropbox.Dropbox
// var input io.ReadCloser
var length int64
var ok bool
var cachedItem interface{}
var s string
if r.URL.Path[1:] == "favicon.ico" {
return
}
cachedItem, ok = Lru.Get(r.URL.Path[5:])
if ok {
item := cachedItem.(cacheItem)
s = item.Value
length = item.Length
} else {
var clientid, clientsecret string
var token, rev string
clientid = os.Getenv("CLIENTID")
clientsecret = os.Getenv("CLIENTSECRET")
token = os.Getenv("TOKEN")
// 1. Create a new dropbox object.
db = dropbox.NewDropbox()
// 2. Provide your clientid and clientsecret (see prerequisite).
db.SetAppInfo(clientid, clientsecret)
// 3. Provide the user token.
db.SetAccessToken(token)
rev = ""
//h := md5.New()
//io.WriteString(h, r.URL.Path[5:])
//b := h.Sum(nil)
str := strings.Replace(r.URL.Path[5:], "/", "-", -1)
err = db.DownloadToFile("/"+r.URL.Path[5:], "/tmp/"+str, rev)
if err != nil {
fmt.Printf("123 Error: %s Url: %s Size: \n", err, r.URL.Path[5:], r.URL.Path[1:2])
} else {
dat, err := ioutil.ReadFile("/tmp/" + str)
if err != nil {
} else {
f, err := os.Open("/tmp/" + str)
if err != nil {
}
fi, err := f.Stat()
if err != nil {
// Could not obtain stat, handle error
}
length = fi.Size()
s = string(dat[:])
// w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10))
fmt.Fprintf(w, "%s", dat)
Lru.Add(r.URL.Path[5:], cacheItem{Value: s, Length: length})
}
}
}
w.Header().Set("Content-Length", strconv.FormatInt(length, 10))
fmt.Fprintf(w, "%s", s)
}
开发者ID:shaunmza,项目名称:dbthumbnails,代码行数:71,代码来源:dbthumbnails.go
注:本文中的github.com/stacktic/dropbox.Dropbox类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论