package main import ( "encoding/json" "log" "os" "path/filepath" "time" ) func writemeta(filename string, expiry int64) error { f, _ := os.Open(filename) stat, _ := f.Stat() size := stat.Size() f.Close() if expiry < 0 { expiry = conf.expiry } meta := metadata{ Filename: filepath.Base(filename), Size: size, Expiry: time.Now().Unix() + expiry, } if verbose { log.Printf("Saving metadata for %s in %s", meta.Filename, conf.metapath+"/"+meta.Filename+".json") } f, err := os.Create(conf.metapath + "/" + meta.Filename + ".json") if err != nil { return err } defer f.Close() j, err := json.Marshal(meta) if err != nil { return err } _, err = f.Write(j) return err }