本文整理匯總了Golang中github.com/MG-RAST/Shock/shock-client/lib.Node.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Create方法的具體用法?Golang Node.Create怎麽用?Golang Node.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/Shock/shock-client/lib.Node
的用法示例。
在下文中一共展示了Node.Create方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pcreate
func pcreate(args []string) (err error) {
n := lib.Node{}
var filename string
if ne(conf.Flags["full"]) {
filename = (*conf.Flags["full"])
} else {
helpf("pcreate requires file path: -full=<u>")
}
var filesize int64
fh, err := os.Open(filename)
if err != nil {
handleString(fmt.Sprintf("Error open file: %s\n", err.Error()))
}
if fi, _ := fh.Stat(); err == nil {
filesize = fi.Size()
}
chunks := int(filesize / (conf.CHUNK_SIZE))
if filesize%conf.CHUNK_SIZE != 0 {
chunks += 1
}
if chunks == 1 {
opts := lib.Opts{}
opts["upload_type"] = "full"
opts["full"] = filename
if err := n.Create(opts); err != nil {
handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
} else {
n.PP()
}
} else {
threads, _ := strconv.Atoi(*conf.Flags["threads"])
if threads == 0 {
threads = 1
}
//create node
opts := lib.Opts{}
opts["upload_type"] = "parts"
opts["parts"] = strconv.Itoa(chunks)
if err := n.Create(opts); err != nil {
handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
}
workers := pool.New(threads)
workers.Run()
for i := 0; i < chunks; i++ {
size := int64(conf.CHUNK_SIZE)
if size*(int64(i)+1) > filesize {
size = filesize - size*(int64(i))
}
workers.Add(uploader, n, (i + 1), fh, size)
}
workers.Wait()
maxRetries := 10
for i := 1; i <= maxRetries; i++ {
errCount := 0
completed_jobs := workers.Results()
for _, job := range completed_jobs {
if job.Result != nil {
err := job.Result.(error)
println("Chunk", job.Args[1].(int), "error:", err.Error())
workers.Add(job.F, job.Args...)
errCount++
}
}
if errCount == 0 {
println("All chunks successfully upload.")
break
} else {
println("Retry", i, "of", maxRetries)
workers.Wait()
}
}
workers.Stop()
n.Get()
n.PP()
}
return
}
示例2: main
func main() {
if len(os.Args) == 1 || os.Args[1] == "help" {
helpf("")
}
cmd := os.Args[1]
args := conf.Initialize(os.Args[2:])
setToken(false)
switch cmd {
case "create", "update":
n := lib.Node{}
if cmd == "update" {
if len(args) != 1 {
helpf("update requires <id>")
} else {
n.Id = args[0]
}
}
opts := lib.Opts{}
if ne(conf.Flags["attributes"]) {
opts["attributes"] = (*conf.Flags["attributes"])
}
if t, err := fileOptions(conf.Flags); err != nil {
helpf(err.Error())
} else {
if t == "part" {
if cmd == "create" {
helpf("part option only usable with update")
}
if !ne(conf.Flags["file"]) {
helpf("part option requires file")
}
opts["upload_type"] = t
opts["part"] = (*conf.Flags["part"])
opts["file"] = (*conf.Flags["file"])
if err := n.Update(opts); err != nil {
handleString(fmt.Sprintf("Error updating %s: %s\n", n.Id, err.Error()))
} else {
n.PP()
}
} else {
if t != "" {
opts["upload_type"] = t
opts[t] = (*conf.Flags[t])
if cmd == "create" {
if err := n.Create(opts); err != nil {
handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
} else {
n.PP()
}
} else {
if err := n.Update(opts); err != nil {
handleString(fmt.Sprintf("Error updating %s: %s\n", n.Id, err.Error()))
} else {
n.PP()
}
}
} else {
if err := n.Create(opts); err != nil {
handleString(fmt.Sprintf("Error creating node: %s\n", err.Error()))
} else {
n.PP()
}
}
}
}
case "pcreate":
pcreate(args)
case "get":
if len(args) != 1 {
helpf("get requires <id>")
}
n := lib.Node{Id: args[0]}
if err := n.Get(); err != nil {
fmt.Printf("Error retrieving %s: %s\n", n.Id, err.Error())
} else {
n.PP()
}
case "download":
if len(args) < 1 {
helpf("download requires <id>")
}
index := conf.Flags["index"]
parts := conf.Flags["parts"]
indexOptions := conf.Flags["index_options"]
opts := lib.Opts{}
if ne(index) || ne(parts) || ne(indexOptions) {
if ne(index) && ne(parts) {
opts["index"] = (*index)
opts["parts"] = (*parts)
if ne(indexOptions) {
opts["index_options"] = (*indexOptions)
}
} else {
helpf("index and parts options must be used together")
}
}
n := lib.Node{Id: args[0]}
//.........這裏部分代碼省略.........
示例3: main
func main() {
args := flag.Args()
if *conf.Examples {
helpf("Coming soon.")
}
if len(args) == 0 {
helpf("")
}
switch args[0] {
case "create", "update":
n := lib.Node{}
if args[0] == "update" {
if len(args) != 2 {
helpf("update requires <id>")
} else {
n.Id = args[1]
}
}
opts := lib.Opts{}
if ne(conf.Flags["attributes"]) {
opts["attributes"] = (*conf.Flags["attributes"])
}
if t, err := fileOptions(conf.Flags); err != nil {
helpf(err.Error())
} else {
if t == "part" {
if args[0] == "create" {
helpf("part option only usable with update")
}
if !ne(conf.Flags["file"]) {
helpf("part option requires file")
}
opts["upload_type"] = t
opts["part"] = (*conf.Flags["part"])
opts["file"] = (*conf.Flags["file"])
if err := n.Update(opts); err != nil {
fmt.Printf("Error updating %s: %s\n", n.Id, err.Error())
} else {
n.PP()
}
} else {
if t != "" {
opts["upload_type"] = t
opts[t] = (*conf.Flags[t])
if args[0] == "create" {
if err := n.Create(opts); err != nil {
fmt.Printf("Error creating node: %s\n", err.Error())
} else {
n.PP()
}
} else {
if err := n.Update(opts); err != nil {
fmt.Printf("Error updating %s: %s\n", n.Id, err.Error())
} else {
n.PP()
}
}
} else {
if err := n.Create(opts); err != nil {
fmt.Printf("Error creating node: %s\n", err.Error())
} else {
n.PP()
}
}
}
}
case "get":
if len(args) != 2 {
helpf("get requires <id>")
}
n := lib.Node{Id: args[1]}
if err := n.Get(); err != nil {
fmt.Printf("Error retrieving %s: %s\n", n.Id, err.Error())
} else {
n.PP()
}
case "download":
if len(args) < 2 {
helpf("download requires <id>")
}
index := conf.Flags["index"]
parts := conf.Flags["parts"]
indexOptions := conf.Flags["index_options"]
opts := lib.Opts{}
if ne(index) || ne(parts) || ne(indexOptions) {
if ne(index) && ne(parts) {
opts["index"] = (*index)
opts["parts"] = (*parts)
if ne(indexOptions) {
opts["index_options"] = (*indexOptions)
}
} else {
helpf("index and parts options must be used together")
}
}
n := lib.Node{Id: args[1]}
if ih, err := n.Download(opts); err != nil {
fmt.Printf("Error downloading %s: %s\n", n.Id, err.Error())
} else {
//.........這裏部分代碼省略.........