當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Response.Error方法代碼示例

本文整理匯總了Golang中minicli.Response.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response.Error方法的具體用法?Golang Response.Error怎麽用?Golang Response.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在minicli.Response的用法示例。


在下文中一共展示了Response.Error方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dnsmasqHostInfo

func dnsmasqHostInfo(c *minicli.Command, resp *minicli.Response) {
	// print info about the mapping
	resp.Header = []string{"ID", "MAC", "IP"}
	resp.Tabular = [][]string{}
	if c.StringArgs["ID"] == Wildcard {
		for id, v := range dnsmasqServers {
			for mac, ip := range v.DHCPhosts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), mac, ip})
			}
		}
	} else {
		id, err := strconv.Atoi(c.StringArgs["ID"])
		if err != nil {
			resp.Error = "Invalid dnsmasq ID"
			return
		}
		if _, ok := dnsmasqServers[id]; ok {
			for mac, ip := range dnsmasqServers[id].DHCPhosts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), mac, ip})
			}
		} else {
			resp.Error = "Invalid dnsmasq ID"
		}
	}
}
開發者ID:jenareljam,項目名稱:minimega,代碼行數:25,代碼來源:dnsmasq.go

示例2: dnsmasqDNSInfo

func dnsmasqDNSInfo(c *minicli.Command, resp *minicli.Response) {
	// print info
	resp.Header = []string{"ID", "IP", "Hostname"}
	resp.Tabular = [][]string{}
	if c.StringArgs["ID"] == Wildcard {
		for id, v := range dnsmasqServers {
			for ip, host := range v.Hostnames {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ip, host})
			}
		}
	} else {
		id, err := strconv.Atoi(c.StringArgs["ID"])
		if err != nil {
			resp.Error = "Invalid dnsmasq ID"
			return
		}
		if _, ok := dnsmasqServers[id]; ok {
			for ip, host := range dnsmasqServers[id].Hostnames {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ip, host})
			}
		} else {
			resp.Error = "Invalid dnsmasq ID"
		}
	}
}
開發者ID:jenareljam,項目名稱:minimega,代碼行數:25,代碼來源:dnsmasq.go

示例3: cliShell

func cliShell(c *minicli.Command, resp *minicli.Response, background bool) error {
	var sOut bytes.Buffer
	var sErr bytes.Buffer

	p, err := exec.LookPath(c.ListArgs["command"][0])
	if err != nil {
		return err
	}

	args := []string{p}
	if len(c.ListArgs["command"]) > 1 {
		args = append(args, c.ListArgs["command"][1:]...)
	}

	cmd := &exec.Cmd{
		Path:   p,
		Args:   args,
		Env:    nil,
		Dir:    "",
		Stdout: &sOut,
		Stderr: &sErr,
	}
	log.Info("starting: %v", args)
	if err := cmd.Start(); err != nil {
		return err
	}

	if background {
		go func() {
			if err := cmd.Wait(); err != nil {
				log.Error(err.Error())
				return
			}

			log.Info("command %v exited", args)
			if out := sOut.String(); out != "" {
				log.Info(out)
			}
			if err := sErr.String(); err != "" {
				log.Info(err)
			}
		}()

		return nil
	}

	if err = cmd.Wait(); err != nil {
		return err
	}

	resp.Response = sOut.String()
	resp.Error = sErr.String()

	return nil
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:55,代碼來源:shell.go

示例4: dnsmasqDHCPOptionInfo

func dnsmasqDHCPOptionInfo(c *minicli.Command, resp *minicli.Response) {
	resp.Header = []string{"ID", "Option"}
	resp.Tabular = [][]string{}
	if c.StringArgs["ID"] == Wildcard {
		for id, v := range dnsmasqServers {
			for _, ent := range v.DHCPopts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ent})
			}
		}
	} else {
		id, err := strconv.Atoi(c.StringArgs["ID"])
		if err != nil {
			resp.Error = "Invalid dnsmasq ID"
			return
		}
		if _, ok := dnsmasqServers[id]; ok {
			for _, ent := range dnsmasqServers[id].DHCPopts {
				resp.Tabular = append(resp.Tabular, []string{strconv.Itoa(id), ent})
			}
		} else {
			resp.Error = "Invalid dnsmasq ID"
		}
	}
}
開發者ID:jenareljam,項目名稱:minimega,代碼行數:24,代碼來源:dnsmasq.go

示例5: cliVyatta

func cliVyatta(c *minicli.Command, resp *minicli.Response) error {
	log.Warnln("the vyatta API is deprecated and will be removed in a future release")

	if c.BoolArgs["dhcp"] {
		net := c.StringArgs["network"]

		if len(c.StringArgs) == 0 {
			// List the existing DHCP services
			resp.Header = []string{"Network", "GW", "Start address", "Stop address", "DNS"}
			resp.Tabular = [][]string{}
			for k, v := range vyatta.Dhcp {
				resp.Tabular = append(resp.Tabular, []string{k, v.Gw, v.Start, v.Stop, v.Dns})
			}
		} else if c.StringArgs["gateway"] != "" {
			// Add a new DHCP service
			vyatta.Dhcp[net] = &vyattaDhcp{
				Gw:    c.StringArgs["gateway"],
				Start: c.StringArgs["low"],
				Stop:  c.StringArgs["high"],
				Dns:   c.StringArgs["dns"],
			}

			log.Debug("vyatta add dhcp %v", vyatta.Dhcp[net])
		} else {
			// Deleting a DHCP service
			if _, ok := vyatta.Dhcp[net]; !ok {
				resp.Error = "no such Dhcp service"
			} else {
				log.Debug("vyatta delete dhcp %v", net)
				delete(vyatta.Dhcp, net)
			}
		}
	} else if c.BoolArgs["interfaces"] {
		// Get or update IPv4 interfaces
		if len(c.ListArgs) == 0 {
			resp.Response = fmt.Sprintf("%v", vyatta.Ipv4)
		} else {
			vyatta.Ipv4 = c.ListArgs["net"]
		}
	} else if c.BoolArgs["interfaces6"] {
		// Get or update IPv6 interfaces
		if len(c.ListArgs) == 0 {
			resp.Response = fmt.Sprintf("%v", vyatta.Ipv6)
		} else {
			vyatta.Ipv6 = c.ListArgs["net"]
		}
	} else if c.BoolArgs["rad"] {
		// Get or update rad
		if len(c.ListArgs) == 0 {
			resp.Response = fmt.Sprintf("%v", vyatta.Rad)
		} else {
			vyatta.Rad = c.ListArgs["prefix"]
		}
	} else if c.BoolArgs["ospf"] {
		// Get or update ospf
		if len(c.ListArgs) == 0 {
			resp.Response = fmt.Sprintf("%v", vyatta.Ospf)
		} else {
			vyatta.Ospf = c.ListArgs["network"]
		}
	} else if c.BoolArgs["ospf3"] {
		// Get or update ospf
		if len(c.ListArgs) == 0 {
			resp.Response = fmt.Sprintf("%v", vyatta.Ospf3)
		} else {
			vyatta.Ospf3 = c.ListArgs["network"]
		}
	} else if c.BoolArgs["routes"] {
		if len(c.ListArgs) == 0 {
			resp.Header = []string{"Network", "Route"}
			resp.Tabular = [][]string{}

			for _, v := range vyatta.Routes {
				resp.Tabular = append(resp.Tabular, []string{v.Route, v.NextHop})
			}
		} else {
			err := vyattaUpdateRoutes(c.ListArgs["network"])
			if err != nil {
				resp.Error = err.Error()
			}
		}
	} else if c.BoolArgs["config"] {
		// override everything and just cram the listed file into the floppy
		// image
		if len(c.StringArgs) == 0 {
			resp.Response = vyatta.ConfigFile
		} else {
			vyatta.ConfigFile = c.StringArgs["filename"]
		}
	} else if c.BoolArgs["write"] {
		var err error
		resp.Response, err = vyattaWrite(c.StringArgs["filename"])
		if err != nil {
			resp.Error = err.Error()
		}
	} else {
		// Display info about running services
		var dhcpKeys []string
		for k, _ := range vyatta.Dhcp {
			dhcpKeys = append(dhcpKeys, k)
//.........這裏部分代碼省略.........
開發者ID:cdshann,項目名稱:minimega,代碼行數:101,代碼來源:vyatta.go


注:本文中的minicli.Response.Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。