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


Golang fmt.Sscanln函數代碼示例

本文整理匯總了Golang中fmt.Sscanln函數的典型用法代碼示例。如果您正苦於以下問題:Golang Sscanln函數的具體用法?Golang Sscanln怎麽用?Golang Sscanln使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: parseLine

// Parse an individual line from Linux's /proc/net/dev.
func (nic *NICSampler) parseLine(line string) (err error) {
	var dev string
	var rx_byte, rx_pkt, rx_err, rx_drop uint64
	var rx_fifo, rx_frame, rx_comp, rx_mcast uint64
	var tx_byte, tx_pkt, tx_err, tx_drop uint64
	var tx_fifo, tx_coll, tx_carr, tx_comp uint64

	if strings.Contains(line, "|") {
		return
	}
	_, err = fmt.Sscanln(line,
		&dev,
		&rx_byte, &rx_pkt, &rx_err, &rx_drop,
		&rx_fifo, &rx_frame, &rx_comp, &rx_mcast,
		&tx_byte, &tx_pkt, &tx_err, &tx_drop,
		&tx_fifo, &tx_coll, &tx_carr, &tx_comp)
	if err != nil {
		return
	}
	dev = dev[0 : len(dev)-1]
	if strings.HasPrefix(dev, "lo") {
		return
	}
	nic.sink.Write("net",
		dev,
		rx_byte, rx_pkt, rx_err, rx_drop,
		tx_byte, tx_pkt, tx_err, tx_drop)
	return
}
開發者ID:codeslinger,項目名稱:monitor,代碼行數:30,代碼來源:standard.go

示例2: Scanln

func (fakeUi *FakeUi) Scanln(args ...interface{}) (int, error) {
	fakeUi.Args = args

	fmt.Sscanln(fakeUi.UserInput, args[0])

	return fakeUi.ScanlnRc, fakeUi.ScanlnErr
}
開發者ID:cloudfoundry-community,項目名稱:bosh-softlayer-tools,代碼行數:7,代碼來源:fake_ui.go

示例3: GetOwner

// Who owns the lockfile?
func (l Lockfile) GetOwner() (*os.Process, error) {
	name := string(l)

	// Ok, see, if we have a stale lockfile here
	content, err := ioutil.ReadFile(name)
	if err != nil {
		return nil, err
	}

	var pid int
	_, err = fmt.Sscanln(string(content), &pid)
	if err != nil {
		return nil, ErrInvalidPid
	}

	// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
	if pid > 0 {
		p, err := os.FindProcess(pid)
		if err != nil {
			return nil, err
		}
		return p, isProcessAlive(p)
	} else {
		return nil, ErrInvalidPid
	}
	panic("Not reached")
}
開發者ID:kovetskiy,項目名稱:lockfile,代碼行數:28,代碼來源:lockfile.go

示例4: boxFromString

// boxFromString returns the box defined by a string of the form "x y w h id".
func boxFromString(in string) (b box, err error) {
	_, err = fmt.Sscanln(in, &b.x, &b.y, &b.w, &b.l, &b.id)
	if b == emptybox {
		return b, errEmpty
	}
	if b.w == 0 && b.l == 0 {
		return b, errZeroBox
	}
	return
}
開發者ID:billyboar,項目名稱:GCSolutions,代碼行數:11,代碼來源:pallet.go

示例5: main

func main() {
	str := "34  343  245"
	var a, b, c int
	fmt.Sscan(str, &a, &b, &c)
	fmt.Println(a, b, c)
	fmt.Sscanf(str, "%d %d %d", &a, &b, &c)
	fmt.Println(a, b, c)
	fmt.Sscanln(str, &a, &b, &c)
	fmt.Println(a, b, c)
}
開發者ID:cwen-coder,項目名稱:study-gopkg,代碼行數:10,代碼來源:Sscan.go

示例6: readLockfile

func readLockfile(path string) (pid int, err error) {
	d, err := ioutil.ReadFile(path)
	if os.IsNotExist(err) {
		return 0, nil
	}
	if err != nil {
		return 0, err
	}
	if _, err := fmt.Sscanln(string(d), &pid); err != nil {
		return 0, ErrReadingLockfile
	}
	return pid, nil
}
開發者ID:nicolasleger,項目名稱:heroku-cli,代碼行數:13,代碼來源:lock.go

示例7: main

func main() {
	cgreader.RunStaticProgram(
		"../../input/ascii_4.txt",
		"../../output/ascii_4.txt",
		true,
		func(input <-chan string, output chan string) {
			var width, height int
			var text string

			fmt.Sscanln(<-input, &width)
			fmt.Sscanln(<-input, &height)
			fmt.Sscanln(<-input, &text)

			text = strings.ToUpper(text)

			ascii := make([]string, height)
			for i := 0; i < height; i++ {
				ascii[i] = <-input
			}

			lines := make([]string, height)
			for _, char := range text {
				character := int(char) - 65
				if character < 0 || character > 26 {
					character = 26
				}
				for i := range lines {
					position := character * width
					lines[i] += ascii[i][position : position+width]
				}
			}

			for _, line := range lines {
				output <- fmt.Sprintln(line)
			}
		})
}
開發者ID:shawshining,項目名稱:Codingame,代碼行數:37,代碼來源:ascii_art.go

示例8: Update

// Update from /proc/stst
func (s *procStat) Update() (st procStat, err error) {
	data, err := readFile(filepath.Join(PROC_DIR, "stat"))
	if err != nil {
		log.Println(err)
		return
	}
	var ig string
	fmt.Sscanln(string(data), &ig, &s.User, &s.Nice, &s.Sys, &s.Idle, &s.Iowait, &s.Irq, &s.Softirq)
	st = *s
	// Cpu Count
	re, _ := regexp.Compile("\ncpu[0-9]")
	s.Ncpu = len(re.FindAllString(string(data), 100))
	s.timeStamp = time.Now()
	return
}
開發者ID:mehulsbhatt,項目名稱:monitor,代碼行數:16,代碼來源:monitor.go

示例9: main

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Enter text: ")
	text, _ := reader.ReadString('\n')
	fmt.Println(text)

	fmt.Println("Enter text: ")
	text2 := ""
	fmt.Scanln(text2)
	fmt.Println(text2)

	ln := ""
	fmt.Sscanln("%v", ln)
	fmt.Println(ln)
}
開發者ID:voltron42,項目名稱:rpgPractice,代碼行數:15,代碼來源:io.go

示例10: scanPidLine

func scanPidLine(content []byte) (int, error) {
	if len(content) == 0 {
		return 0, ErrInvalidPid
	}

	var pid int
	if _, err := fmt.Sscanln(string(content), &pid); err != nil {
		return 0, ErrInvalidPid
	}

	if pid <= 0 {
		return 0, ErrInvalidPid
	}
	return pid, nil
}
開發者ID:nightlyone,項目名稱:lockfile,代碼行數:15,代碼來源:lockfile.go

示例11: toRat

// toRat converts a Value to rat. A str can be converted to a rat if it can be
// parsed. A rat is returned as-is. Other types of values cannot be converted.
func toRat(v Value) (rat, error) {
	switch v := v.(type) {
	case rat:
		return v, nil
	case str:
		r := big.Rat{}
		_, err := fmt.Sscanln(string(v), &r)
		if err != nil {
			return rat{}, fmt.Errorf("%s cannot be parsed as rat", v.Repr())
		}
		return rat{&r}, nil
	default:
		return rat{}, errOnlyStrOrRat
	}
}
開發者ID:earneet,項目名稱:elvish,代碼行數:17,代碼來源:value.go

示例12: str

func str() {
	var a int
	var b int

	log.Printf("a: %d, b: %d", a, b)
	fmt.Sscan("20\n20", &a, &b)
	log.Printf("a: %d, b: %d", a, b)

	fmt.Sscanf("(15, 30)", "(%d, %d)", &a, &b)
	log.Printf("a: %d, b: %d", a, b)

	// Will not go past the newline, only scans a
	fmt.Sscanln("10\n10", &a, &b)
	log.Printf("a: %d, b: %d", a, b)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:15,代碼來源:scanning.go

示例13: getSystemUptime

// Returns system uptime as time.Duration.
func getSystemUptime() (uptime time.Duration, err error) {
	buf, err := ioutil.ReadFile("/proc/uptime")
	if err != nil {
		return uptime, err
	}
	var up, idle float64
	n, err := fmt.Sscanln(string(buf), &up, &idle)
	if err != nil {
		return uptime, err
	}
	if n != 2 {
		return uptime, errors.New("failed parsing /proc/uptime")
	}
	uptime = time.Duration(up) * time.Second

	return uptime, nil
}
開發者ID:0987363,項目名稱:zfswatcher,代碼行數:18,代碼來源:osutil_linux.go

示例14: main

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	timetable := readTimetable(scanner)

	var departureStation, arrivalStation, departureTime uint32
	for scanner.Scan() {
		if len(scanner.Text()) == 0 {
			os.Exit(0)
		} else {
			_, err := fmt.Sscanln(scanner.Text(), &departureStation, &arrivalStation, &departureTime)
			if err != nil {
				panic(err)
			}
			timetable.compute(departureStation, arrivalStation, departureTime)
		}
	}
}
開發者ID:brechtvdv,項目名稱:csa-challenge,代碼行數:18,代碼來源:csa.go

示例15: GetOwner

// Who owns the lockfile?
func (l Lockfile) GetOwner() (*os.Process, error) {
	name := string(l)

	// Ok, see, if we have a stale lockfile here
	content, err := ioutil.ReadFile(name)
	if err != nil {
		return nil, err
	}

	var pid int
	_, err = fmt.Sscanln(string(content), &pid)
	if err != nil {
		return nil, err
	}

	// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
	if pid > 0 {
		p, err := os.FindProcess(pid)
		if err != nil {
			return nil, err
		}
		err = p.Signal(os.Signal(syscall.Signal(0)))
		if err == nil {
			return p, nil
		}
		errno, ok := err.(syscall.Errno)
		if !ok {
			return nil, err
		}

		switch errno {
		case syscall.ESRCH:
			return nil, ErrDeadOwner
		case syscall.EPERM:
			return p, nil
		default:
			return nil, err
		}
	} else {
		return nil, ErrInvalidPid
	}
	panic("Not reached")
}
開發者ID:mlafeldt,項目名稱:remote_syslog2,代碼行數:44,代碼來源:lockfile.go


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