本文整理汇总了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
}
示例2: Scanln
func (fakeUi *FakeUi) Scanln(args ...interface{}) (int, error) {
fakeUi.Args = args
fmt.Sscanln(fakeUi.UserInput, args[0])
return fakeUi.ScanlnRc, fakeUi.ScanlnErr
}
示例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")
}
示例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
}
示例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)
}
示例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
}
示例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)
}
})
}
示例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
}
示例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)
}
示例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
}
示例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
}
}
示例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)
}
示例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
}
示例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)
}
}
}
示例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")
}