2013年6月4日 星期二

GO lang學習筆記(12)

package main

import (
    "fmt"
    "math/cmplx"
)

var (
    ToBe   bool       = false
    MaxInt uint64     = 1<<64 - 1
    z      complex128 = cmplx.Sqrt(-5 + 12i)
)

func main() {
    const f = "%T(%v)\n"
    fmt.Printf(f, ToBe, ToBe)
    fmt.Printf(f, MaxInt, MaxInt)
    fmt.Printf(f, z, z)
}

將常數 f 定義為 %T(%v)
常數使用 const 關鍵字,常數值可以為 字元、字串、布林、數字 類型。

%T 為顯示 type (EX:int, float)
%v 為顯示 其值

GO lang學習筆記(9)

package main

import "fmt"

func swap(x, y string) (string, string) {
    return y, x
}

func c(x, y int)(sx,sy int){
    sx = y*x
    sy = -y*x
return 
}
func main() {
    a, b := swap("hello", "world")
    fmt.Println(a, b)
 
    fmt.Println(c(1, 2))
}

當沒有 return 值時,會將 function 定義 (sx,sy int) 以 string 形式 return

用 fmt.Println(c(1, 2)) 印出

GO lang 學習筆記 (8)

package main

import "fmt"

func swap(x, y string) (string, string) {
    return y, x
}

func c(x, y int) (int,int){ //注意return 個數定義
return y*x, -y*x
}

func main() {
    a, b := swap("hello", "world")
    fmt.Println(a, b)
    x, y := c(1, 2)
   
    fmt.Printf("%d,%d",x,y)
}

Swift-curl格式

參考網址:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/storage-account-services.html
http://docs.openstack.org/trunk/openstack-compute/starter/content/ch05s01s02.html

以下操作皆可用 'swift' 指令 "swift --help" 查詢

獲得  X-Auth-Token
curl -v -H 'X-Storage-User: admin:admin' -H 'X-Storage-Pass: admin' http://10.10.10.2:8080/auth/v1.0

舉例,獲得的 X-Auth-Token:AUTH_tk3bb59eda987446c79160202d4dfbdc8c。其餘指令若須使用 X-Auth-Token 則帶入 "AUTH_tk3bb59eda987446c79160202d4dfbdc8c"。

To create a container:
curl -X PUT -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer
To list all containers in current account:
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/
Uploading a file "file1" to container "mycontainer"
curl -X PUT -T file1 -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer/
To list all objects in a container:
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer

To list all objects in a container that starts with a particular prefix "fi":
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer/?prefix=fi 

To download a particular file "file1" from the container "mycontainer":
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer/file1

To download file1 and save it locally as localfile1:
curl -o localfile1 -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer/file1

To delete a container "mycontainer"
curl -X DELETE -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer

To delete a specific file "file1" from the container:
curl -X DELETE -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer/file1

To get metadata associated with a Swift account:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/

To get metadata associated with a container:
curl -v -X HEAD -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/mycontainer

You can request the data from Swift in XML or JSON format by specifying the "format" paramater. This parameter can be applied to any of the above requests. Here are a few examples:
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/?format=json
curl -H 'X-Auth-Token: AUTH_tk3bb59eda987446c79160202d4dfbdc8c' http://10.10.10.2:8080/v1/AUTH_admin/?format=xml