本文整理匯總了Golang中github.com/imc-trading/dock2box/client.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateTagCommandFunc
func updateTagCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a tag")
}
tag := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Tag.Get(tag)
if err != nil {
log.Fatal(err.Error())
}
if c.Bool("prompt") {
s := client.Tag{
ID: v.ID,
Tag: prompt.String("Image", prompt.Prompt{Default: v.Tag, FuncPtr: prompt.Regex, FuncInp: ""}),
Created: prompt.String("Created", prompt.Prompt{Default: v.Created, FuncPtr: prompt.Regex, FuncInp: ""}),
SHA256: prompt.String("SHA256", prompt.Prompt{Default: v.SHA256, FuncPtr: prompt.Regex, FuncInp: "^[0-9a-f]+$"}),
ImageID: *chooseImage(clnt, v.ImageID),
}
// Update tag
clnt.Tag.Update(tag, &s)
return
}
}
示例2: createTenantCommandFunc
func createTenantCommandFunc(c *cli.Context) {
var tenant string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a tenant")
} else {
tenant = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
s := client.Tenant{
Tenant: tenant,
}
// Is this correct?
fmt.Println(string(s.JSON()))
if !prompt.Bool("Is this correct", true) {
os.Exit(1)
}
// Create tenant
clnt.Tenant.Create(&s)
return
}
示例3: createImageCommandFunc
func createImageCommandFunc(c *cli.Context) {
var image string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a image")
} else {
image = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
if c.Bool("prompt") {
s := client.Image{
Image: image,
Type: prompt.String("Type", prompt.Prompt{Default: "docker", FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
BootTagID: *chooseTag(clnt, ""),
}
// Create image
clnt.Image.Create(&s)
return
}
}
示例4: createSiteCommandFunc
func createSiteCommandFunc(c *cli.Context) {
var site string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a site")
} else {
site = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
if c.Bool("prompt") {
s := client.Site{
Site: site,
Domain: prompt.String("Domain", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
DNS: strings.Split(prompt.String("DNS", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4List, FuncInp: ""}), ","),
DockerRegistry: prompt.String("Docker Registry", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
ArtifactRepository: prompt.String("Artifact Repository", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
NamingScheme: prompt.String("Naming Scheme", prompt.Prompt{Default: "hardware-address", FuncPtr: prompt.Enum, FuncInp: "serial-number,hardware-address,external"}),
PXETheme: prompt.String("PXE Theme", prompt.Prompt{Default: "night", FuncPtr: prompt.Regex, FuncInp: ""}),
}
// Create site
clnt.Site.Create(&s)
return
}
}
示例5: updateSubnetCommandFunc
func updateSubnetCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a subnet")
}
subnet := strings.Replace(c.Args()[0], "/", "-", 1)
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Subnet.Get(subnet)
if err != nil {
log.Fatal(err.Error())
}
s := client.Subnet{
ID: v.ID,
Subnet: prompt.String("Subnet", prompt.Prompt{Default: v.Subnet, FuncPtr: prompt.Regex, FuncInp: ""}),
Mask: prompt.String("Mask", prompt.Prompt{Default: v.Mask, FuncPtr: validateIPv4, FuncInp: ""}),
Gw: prompt.String("Gateway", prompt.Prompt{Default: v.Gw, FuncPtr: validateIPv4, FuncInp: ""}),
SiteID: *chooseSite(clnt, v.SiteID),
}
// Create subnet
clnt.Subnet.Update(subnet, &s)
}
示例6: updateImageCommandFunc
func updateImageCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a image")
}
image := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Image.Get(image)
if err != nil {
log.Fatal(err.Error())
}
s := client.Image{
ID: v.ID,
Image: prompt.String("Image", prompt.Prompt{Default: v.Image, FuncPtr: prompt.Regex, FuncInp: ""}),
Type: prompt.String("Type", prompt.Prompt{Default: v.Type, FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
BootTagID: *chooseTag(clnt, v.BootTagID),
}
// Update image
clnt.Image.Update(image, &s)
}
示例7: createTagCommandFunc
func createTagCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a tag")
}
tag := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
s := client.Tag{
Tag: tag,
Created: prompt.String("Created", prompt.Prompt{Default: strftime.Format("%Y-%m-%dT%H:%M:%SZ", time.Now()), FuncPtr: prompt.Regex, FuncInp: ""}),
SHA256: prompt.String("SHA256", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: "^[0-9a-f]+$"}),
ImageID: *chooseImage(clnt, ""),
}
// Is this correct?
fmt.Println(string(s.JSON()))
if !prompt.Bool("Is this correct", true) {
os.Exit(1)
}
// Create image
clnt.Tag.Create(&s)
}
示例8: updateSiteCommandFunc
func updateSiteCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a site")
}
site := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Site.Get(site)
if err != nil {
log.Fatal(err.Error())
}
s := client.Site{
ID: v.ID,
Site: prompt.String("Site", prompt.Prompt{Default: v.Site, FuncPtr: prompt.Regex, FuncInp: ""}),
Domain: prompt.String("Domain", prompt.Prompt{Default: v.Domain, FuncPtr: prompt.Regex, FuncInp: ""}),
DNS: strings.Split(prompt.String("DNS", prompt.Prompt{Default: strings.Join(v.DNS, ","), FuncPtr: validateIPv4List, FuncInp: ""}), ","),
DockerRegistry: prompt.String("Docker Registry", prompt.Prompt{Default: v.DockerRegistry, FuncPtr: prompt.Regex, FuncInp: ""}),
ArtifactRepository: prompt.String("Artifact Repository", prompt.Prompt{Default: v.ArtifactRepository, FuncPtr: prompt.Regex, FuncInp: ""}),
NamingScheme: prompt.String("Naming Scheme", prompt.Prompt{Default: v.NamingScheme, FuncPtr: prompt.Enum, FuncInp: "serial-number,hardware-address,external"}),
PXETheme: prompt.String("PXE Theme", prompt.Prompt{Default: v.PXETheme, FuncPtr: prompt.Regex, FuncInp: ""}),
}
// Create site
clnt.Site.Update(site, &s)
}
示例9: createImageCommandFunc
func createImageCommandFunc(c *cli.Context) {
var image string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a image")
} else {
image = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
s := client.Image{
Image: image,
Type: prompt.String("Type", prompt.Prompt{Default: "docker", FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
BootTagID: *chooseTag(clnt, ""),
}
// Is this correct?
fmt.Println(string(s.JSON()))
if !prompt.Bool("Is this correct", true) {
os.Exit(1)
}
// Create image
clnt.Image.Create(&s)
}
示例10: updateTenantCommandFunc
func updateTenantCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a tenant")
}
tenant := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Tenant.Get(tenant)
if err != nil {
log.Fatal(err.Error())
}
s := client.Tenant{
ID: v.ID,
Tenant: prompt.String("Tenant", prompt.Prompt{Default: v.Tenant, FuncPtr: prompt.Regex, FuncInp: ""}),
}
// Create tenant
clnt.Tenant.Update(tenant, &s)
return
}
示例11: createSubnetCommandFunc
func createSubnetCommandFunc(c *cli.Context) {
var subnet string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a subnet")
} else {
subnet = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
if c.Bool("prompt") {
s := client.Subnet{
Subnet: subnet,
// Calculate automatically based on subnet/prefix
Mask: prompt.String("Mask", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4, FuncInp: ""}),
// Default to .254 for subnet
Gw: prompt.String("Gateway", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4, FuncInp: ""}),
SiteID: *chooseSite(clnt, ""),
}
// Create subnet
clnt.Subnet.Create(&s)
return
}
}
示例12: main
func main() {
c := client.New("http://localhost:8080/v1")
hosts, err := c.Host.All()
if err != nil {
log.Fatalf(err.Error())
}
fmt.Println(hosts.JSON())
}
示例13: getHostsCommandFunc
func getHostsCommandFunc(c *cli.Context) {
clnt := client.New(c.GlobalString("server"))
h, err := clnt.Host.All()
if err != nil {
log.Fatal(err.Error())
}
b, _ := json.MarshalIndent(h, "", " ")
fmt.Printf("%v\n", string(b))
}
示例14: updateHostCommandFunc
func updateHostCommandFunc(c *cli.Context) {
if len(c.Args()) == 0 {
log.Fatal("You need to specify a hostname")
}
hostname := c.Args()[0]
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
v, err := clnt.Host.Get(hostname)
if err != nil {
log.Fatal(err.Error())
}
if c.Bool("prompt") {
h := client.Host{
ID: v.ID,
Host: prompt.String("Host", prompt.Prompt{Default: v.Host, FuncPtr: prompt.Regex, FuncInp: ""}),
Build: prompt.Bool("Build", v.Build),
Debug: prompt.Bool("Debug", v.Debug),
GPT: prompt.Bool("GPT", v.GPT),
TagID: *chooseTag(clnt, v.TagID),
}
// Get labels
labels := prompt.String("Comma-separated list of labels", prompt.Prompt{Default: strings.Join(v.Labels, ","), FuncPtr: prompt.Regex, FuncInp: "^([a-zA-Z][a-zA-Z0-9-]+,)*([a-zA-Z][a-zA-Z0-9-]+)$"})
if labels == "" {
h.Labels = []string{}
} else {
h.Labels = strings.Split(labels, ",")
}
h.KOpts = prompt.String("KOpts", prompt.Prompt{Default: v.KOpts, FuncPtr: prompt.Regex, FuncInp: "^(|[a-zA-Z0-9- ])+$"})
h.TenantID = *chooseTenants(clnt, v.TenantID)
h.SiteID = *chooseSite(clnt, v.SiteID)
/*
for _, v := range v.Interfaces {
h.Interfaces = append(h.Interfaces, updateHostInterface(clnt, h.SiteID, v))
}
*/
// Is this correct?
fmt.Println(string(h.JSON()))
if !prompt.Bool("Is this correct", true) {
os.Exit(1)
}
// Update host
clnt.Host.Update(hostname, &h)
return
}
}
示例15: Example_GetHost
func Example_GetHost() {
server := "http://localhost:8080/v1"
hostname := "test1.example.com"
clnt := client.New(server)
h, err := clnt.Host.Get(hostname)
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("%v\n", string(h.JSON()))
}