当前位置: 首页>>代码示例>>Golang>>正文


Golang i18n.G函数代码示例

本文整理汇总了Golang中github.com/lxc/lxd/i18n.G函数的典型用法代码示例。如果您正苦于以下问题:Golang G函数的具体用法?Golang G怎么用?Golang G使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了G函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: isEphemeralColumnData

func isEphemeralColumnData(cinfo shared.ContainerInfo) string {
	if cinfo.State.Ephemeral {
		return i18n.G("YES")
	} else {
		return i18n.G("NO")
	}
}
开发者ID:hex2a,项目名称:lxd,代码行数:7,代码来源:list.go

示例2: main

func main() {
	if err := run(); err != nil {
		// The action we take depends on the error we get.
		msg := fmt.Sprintf(i18n.G("error: %v"), err)
		switch t := err.(type) {
		case *url.Error:
			switch u := t.Err.(type) {
			case *net.OpError:
				if u.Op == "dial" && u.Net == "unix" {
					switch errno := u.Err.(type) {
					case syscall.Errno:
						switch errno {
						case syscall.ENOENT:
							msg = i18n.G("LXD socket not found; is LXD running?")
						case syscall.ECONNREFUSED:
							msg = i18n.G("Connection refused; is LXD running?")
						case syscall.EACCES:
							msg = i18n.G("Permisson denied, are you in the lxd group?")
						default:
							msg = fmt.Sprintf("%d %s", uintptr(errno), errno.Error())
						}
					}
				}
			}
		}

		fmt.Fprintln(os.Stderr, fmt.Sprintf("%s", msg))
		os.Exit(1)
	}
}
开发者ID:HPCNow,项目名称:lxd,代码行数:30,代码来源:main.go

示例3: execIfAliases

func execIfAliases(config *lxd.Config, origArgs []string) {
	newArgs := []string{}
	expandedAlias := false
	for _, arg := range origArgs {
		changed := false
		for k, v := range config.Aliases {
			if k == arg {
				expandedAlias = true
				changed = true
				newArgs = append(newArgs, strings.Split(v, " ")...)
				break
			}
		}

		if !changed {
			newArgs = append(newArgs, arg)
		}
	}

	if expandedAlias {
		path, err := exec.LookPath(origArgs[0])
		if err != nil {
			fmt.Fprintf(os.Stderr, i18n.G("processing aliases failed %s\n"), err)
			os.Exit(5)
		}
		ret := syscall.Exec(path, newArgs, syscall.Environ())
		fmt.Fprintf(os.Stderr, i18n.G("processing aliases failed %s\n"), ret)
		os.Exit(5)
	}
}
开发者ID:HPCNow,项目名称:lxd,代码行数:30,代码来源:main.go

示例4: run

func (c *actionCmd) run(config *lxd.Config, args []string) error {
	if len(args) == 0 {
		return errArgs
	}

	for _, nameArg := range args {
		remote, name := config.ParseRemoteAndContainer(nameArg)
		d, err := lxd.NewClient(config, remote)
		if err != nil {
			return err
		}

		resp, err := d.Action(name, c.action, timeout, force)
		if err != nil {
			return err
		}

		if resp.Type != lxd.Async {
			return fmt.Errorf(i18n.G("bad result type from action"))
		}

		if err := d.WaitForSuccess(resp.Operation); err != nil {
			return fmt.Errorf("%s\n"+i18n.G("Try `lxc info --show-log %s` for more info"), err, name)
		}
	}
	return nil
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:27,代码来源:action.go

示例5: ProfileDeviceAdd

func (c *Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*Response, error) {
	st, err := c.ProfileConfig(profile)
	if err != nil {
		return nil, err
	}

	newdev := shared.Device{}
	for _, p := range props {
		results := strings.SplitN(p, "=", 2)
		if len(results) != 2 {
			return nil, fmt.Errorf(i18n.G("no value found in %q"), p)
		}
		k := results[0]
		v := results[1]
		newdev[k] = v
	}
	if st.Devices != nil && st.Devices.ContainsName(devname) {
		return nil, fmt.Errorf(i18n.G("device already exists"))
	}
	newdev["type"] = devtype
	if st.Devices == nil {
		st.Devices = shared.Devices{}
	}
	st.Devices[devname] = newdev

	body := shared.Jmap{"config": st.Config, "name": st.Name, "devices": st.Devices}
	return c.put(fmt.Sprintf("profiles/%s", profile), body, Sync)
}
开发者ID:djibi2,项目名称:lxd,代码行数:28,代码来源:client.go

示例6: UserAuthServerCert

func (c *Client) UserAuthServerCert(name string, acceptCert bool) error {
	if !c.scertDigestSet {
		if err := c.Finger(); err != nil {
			return err
		}

		if !c.scertDigestSet {
			return fmt.Errorf(i18n.G("No certificate on this connection"))
		}
	}

	if c.scert != nil {
		return nil
	}

	_, err := c.scertWire.Verify(x509.VerifyOptions{
		DNSName:       name,
		Intermediates: c.scertIntermediates,
	})
	if err == nil {
		// Server trusted by system certificate
		return nil
	}

	if acceptCert == false {
		fmt.Printf(i18n.G("Certificate fingerprint: %x")+"\n", c.scertDigest)
		fmt.Printf(i18n.G("ok (y/n)?") + " ")
		line, err := shared.ReadStdin()
		if err != nil {
			return err
		}

		if len(line) < 1 || line[0] != 'y' && line[0] != 'Y' {
			return fmt.Errorf(i18n.G("Server certificate NACKed by user"))
		}
	}

	// User acked the cert, now add it to our store
	dnam := c.Config.ConfigPath("servercerts")
	err = os.MkdirAll(dnam, 0750)
	if err != nil {
		return fmt.Errorf(i18n.G("Could not create server cert dir"))
	}
	certf := fmt.Sprintf("%s/%s.crt", dnam, c.Name)
	certOut, err := os.Create(certf)
	if err != nil {
		return err
	}

	pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: c.scertWire.Raw})

	certOut.Close()
	return err
}
开发者ID:djibi2,项目名称:lxd,代码行数:54,代码来源:client.go

示例7: doProfileApply

func doProfileApply(client *lxd.Client, c string, p string) error {
	resp, err := client.ApplyProfile(c, p)
	if err == nil {
		if p == "" {
			p = i18n.G("(none)")
		}
		fmt.Printf(i18n.G("Profile %s applied to %s")+"\n", p, c)
	} else {
		return err
	}
	return client.WaitForSuccess(resp.Operation)
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:12,代码来源:profile.go

示例8: run

func (c *deleteCmd) run(config *lxd.Config, args []string) error {
	if len(args) == 0 {
		return errArgs
	}

	for _, nameArg := range args {
		remote, name := config.ParseRemoteAndContainer(nameArg)

		d, err := lxd.NewClient(config, remote)
		if err != nil {
			return err
		}

		if shared.IsSnapshot(name) {
			return c.doDelete(d, name)
		}

		ct, err := d.ContainerStatus(name)
		if err != nil {
			return err
		}

		if ct.Status.StatusCode != 0 && ct.Status.StatusCode != shared.Stopped {
			if !c.force {
				return fmt.Errorf(i18n.G("The container is currently running, stop it first or pass --force."))
			}

			resp, err := d.Action(name, shared.Stop, -1, true)
			if err != nil {
				return err
			}

			op, err := d.WaitFor(resp.Operation)
			if err != nil {
				return err
			}

			if op.StatusCode == shared.Failure {
				return fmt.Errorf(i18n.G("Stopping container failed!"))
			}

			if ct.Ephemeral == true {
				return nil
			}
		}

		if err := c.doDelete(d, name); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:hex2a,项目名称:lxd,代码行数:52,代码来源:delete.go

示例9: execIfAliases

func execIfAliases(config *lxd.Config, origArgs []string) {
	newArgs, expanded := expandAlias(config, origArgs)
	if !expanded {
		return
	}

	path, err := exec.LookPath(origArgs[0])
	if err != nil {
		fmt.Fprintf(os.Stderr, i18n.G("processing aliases failed %s\n"), err)
		os.Exit(5)
	}
	ret := syscall.Exec(path, newArgs, syscall.Environ())
	fmt.Fprintf(os.Stderr, i18n.G("processing aliases failed %s\n"), ret)
	os.Exit(5)
}
开发者ID:hex2a,项目名称:lxd,代码行数:15,代码来源:main.go

示例10: run

func (c *snapshotCmd) run(config *lxd.Config, args []string) error {
	if len(args) < 1 {
		return errArgs
	}

	var snapname string
	if len(args) < 2 {
		snapname = ""
	} else {
		snapname = args[1]
	}

	remote, name := config.ParseRemoteAndContainer(args[0])
	d, err := lxd.NewClient(config, remote)
	if err != nil {
		return err
	}

	// we don't allow '/' in snapshot names
	if shared.IsSnapshot(snapname) {
		return fmt.Errorf(i18n.G("'/' not allowed in snapshot name"))
	}

	resp, err := d.Snapshot(name, snapname, c.stateful)
	if err != nil {
		return err
	}

	return d.WaitForSuccess(resp.Operation)
}
开发者ID:HPCNow,项目名称:lxd,代码行数:30,代码来源:snapshot.go

示例11: usage

func (c *profileCmd) usage() string {
	return i18n.G(
		`Manage configuration profiles.

lxc profile list [filters]                     List available profiles.
lxc profile show <profile>                     Show details of a profile.
lxc profile create <profile>                   Create a profile.
lxc profile copy <profile> <remote>            Copy the profile to the specified remote.
lxc profile set <profile> <key> <value>        Set profile configuration.
lxc profile delete <profile>                   Delete a profile.
lxc profile edit <profile>                     
    Edit profile, either by launching external editor or reading STDIN.
    Example: lxc profile edit <profile> # launch editor
             cat profile.yml | lxc profile edit <profile> # read from profile.yml
lxc profile apply <container> <profiles>
    Apply a comma-separated list of profiles to a container, in order.
    All profiles passed in this call (and only those) will be applied
    to the specified container.
    Example: lxc profile apply foo default,bar # Apply default and bar
             lxc profile apply foo default # Only default is active
             lxc profile apply '' # no profiles are applied anymore
             lxc profile apply bar,default # Apply default second now

Devices:
lxc profile device list <profile>              List devices in the given profile.
lxc profile device show <profile>              Show full device details in the given profile.
lxc profile device remove <profile> <name>     Remove a device from a profile.
lxc profile device add <profile name> <device name> <device type> [key=value]...
    Add a profile device, such as a disk or a nic, to the containers
    using the specified profile.`)
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:31,代码来源:profile.go

示例12: usage

func (c *imageCmd) usage() string {
	return i18n.G(
		`Manipulate container images.

lxc image import <tarball> [rootfs tarball|URL] [target] [--public] [--created-at=ISO-8601] [--expires-at=ISO-8601] [--fingerprint=FINGERPRINT] [prop=value]

lxc image copy [remote:]<image> <remote>: [--alias=ALIAS].. [--copy-aliases] [--public]
lxc image delete [remote:]<image>
lxc image export [remote:]<image>
lxc image info [remote:]<image>
lxc image list [remote:] [filter]
lxc image show [remote:]<image>
lxc image edit [remote:]<image>
    Edit image, either by launching external editor or reading STDIN.
    Example: lxc image edit <image> # launch editor
             cat image.yml | lxc image edit <image> # read from image.yml

Lists the images at specified remote, or local images.
Filters are not yet supported.

lxc image alias create <alias> <target>
lxc image alias delete <alias>
lxc image alias list [remote:]

Create, delete, list image aliases. Example:
lxc remote add store2 images.linuxcontainers.org
lxc image alias list store2:`)
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:28,代码来源:image.go

示例13: doProfileDelete

func doProfileDelete(client *lxd.Client, p string) error {
	err := client.ProfileDelete(p)
	if err == nil {
		fmt.Printf(i18n.G("Profile %s deleted")+"\n", p)
	}
	return err
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:7,代码来源:profile.go

示例14: ImageFromContainer

func (c *Client) ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string) (string, error) {
	source := shared.Jmap{"type": "container", "name": cname}
	if shared.IsSnapshot(cname) {
		source["type"] = "snapshot"
	}
	body := shared.Jmap{"public": public, "source": source, "properties": properties}

	resp, err := c.post("images", body, Async)
	if err != nil {
		return "", err
	}

	jmap, err := c.AsyncWaitMeta(resp)
	if err != nil {
		return "", err
	}

	fingerprint, err := jmap.GetString("fingerprint")
	if err != nil {
		return "", err
	}

	/* add new aliases */
	for _, alias := range aliases {
		c.DeleteAlias(alias)
		err = c.PostAlias(alias, alias, fingerprint)
		if err != nil {
			fmt.Printf(i18n.G("Error adding alias %s")+"\n", alias)
		}
	}

	return fingerprint, nil
}
开发者ID:djibi2,项目名称:lxd,代码行数:33,代码来源:client.go

示例15: deviceAdd

func deviceAdd(config *lxd.Config, which string, args []string) error {
	if len(args) < 5 {
		return errArgs
	}
	remote, name := config.ParseRemoteAndContainer(args[2])

	client, err := lxd.NewClient(config, remote)
	if err != nil {
		return err
	}

	devname := args[3]
	devtype := args[4]
	var props []string
	if len(args) > 5 {
		props = args[5:]
	} else {
		props = []string{}
	}

	var resp *lxd.Response
	if which == "profile" {
		resp, err = client.ProfileDeviceAdd(name, devname, devtype, props)
	} else {
		resp, err = client.ContainerDeviceAdd(name, devname, devtype, props)
	}
	if err != nil {
		return err
	}
	fmt.Printf(i18n.G("Device %s added to %s")+"\n", devname, name)
	if which == "profile" {
		return nil
	}
	return client.WaitForSuccess(resp.Operation)
}
开发者ID:HPCNow,项目名称:lxd,代码行数:35,代码来源:config.go


注:本文中的github.com/lxc/lxd/i18n.G函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。