本文整理汇总了Golang中fmt.Sscanf函数的典型用法代码示例。如果您正苦于以下问题:Golang Sscanf函数的具体用法?Golang Sscanf怎么用?Golang Sscanf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sscanf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parse
func (p *file) parse(name string) bool {
var num uint64
var tail string
_, err := fmt.Sscanf(name, "%d.%s", &num, &tail)
if err == nil {
switch tail {
case "log":
p.t = TypeLog
case "sst":
p.t = TypeTable
case "dbtmp":
p.t = TypeTemp
default:
return false
}
p.num = num
return true
}
n, _ := fmt.Sscanf(name, "MANIFEST-%d%s", &num, &tail)
if n == 1 {
p.t = TypeManifest
p.num = num
return true
}
return false
}
开发者ID:yufeng108,项目名称:goleveldb,代码行数:27,代码来源:file_desc.go
示例2: readCursorPosition
func (ttyfd TTY) readCursorPosition() (int, int) {
ttyfd.write(READ_CURSOR_POSITION)
var chr byte
var nb []byte = make([]byte, 0)
var x, y int
chr, _, _ = ttyfd.Readchr()
if chr != ESC_CHR {
return 0, 0 // something failed !
}
chr, _, _ = ttyfd.Readchr()
if chr != '[' {
return 0, 0 // something failed !
}
for chr != ';' {
chr, _, _ = ttyfd.Readchr()
nb = append(nb, chr)
}
fmt.Sscanf(string(nb), "%d", &x)
nb = make([]byte, 0)
for chr != 'R' {
chr, _, _ = ttyfd.Readchr()
nb = append(nb, chr)
}
fmt.Sscanf(string(nb), "%d", &y)
return x, y
}
开发者ID:gbin,项目名称:screencastinator,代码行数:29,代码来源:ui.go
示例3: Put
/*
The "put" command is for any process that wants to insert a job into the queue.
It comprises a command line followed by the job body:
put <pri> <delay> <ttr> <bytes>\r\n
<data>\r\n
It inserts a job into the client's currently used tube (see the "use" command
below).
- <pri> is an integer < 2**32. Jobs with smaller priority values will be
scheduled before jobs with larger priorities. The most urgent priority is 0;
the least urgent priority is 4,294,967,295.
- <delay> is an integer number of seconds to wait before putting the job in
the ready queue. The job will be in the "delayed" state during this time.
- <ttr> -- time to run -- is an integer number of seconds to allow a worker
to run this job. This time is counted from the moment a worker reserves
this job. If the worker does not delete, release, or bury the job within
<ttr> seconds, the job will time out and the server will release the job.
The minimum ttr is 1. If the client sends 0, the server will silently
increase the ttr to 1.
- <bytes> is an integer indicating the size of the job body, not including the
trailing "\r\n". This value must be less than max-job-size (default: 2**16).
- <data> is the job body -- a sequence of bytes of length <bytes> from the
previous line.
After sending the command line and body, the client waits for a reply, which
may be:
- "INSERTED <id>\r\n" to indicate success.
- <id> is the integer id of the new job
- "BURIED <id>\r\n" if the server ran out of memory trying to grow the
priority queue data structure.
- <id> is the integer id of the new job
- "EXPECTED_CRLF\r\n" The job body must be followed by a CR-LF pair, that is,
"\r\n". These two bytes are not counted in the job size given by the client
in the put command line.
- "JOB_TOO_BIG\r\n" The client has requested to put a job with a body larger
than max-job-size bytes.
- "DRAINING\r\n" This means that the server has been put into "drain mode"
and is no longer accepting new jobs. The client should try another server
or disconnect and try again later.
*/
func (this *BeanstalkdClient) Put(priority uint32, delay, ttr time.Duration, data []byte) (id uint64, err error) {
cmd := fmt.Sprintf("put %d %d %d %d\r\n", priority, uint64(delay.Seconds()), uint64(ttr.Seconds()), len(data))
cmd = cmd + string(data) + string(crnl)
_, reply, err := this.sendReply(cmd)
if err != nil {
return 0, err
}
switch {
case strings.Index(reply, "INSERTED") == 0:
var id uint64
_, perr := fmt.Sscanf(reply, "INSERTED %d\r\n", &id)
return id, perr
case strings.Index(reply, "BURIED") == 0:
var id uint64
_, perr := fmt.Sscanf(reply, "BURIED %d\r\n", &id)
return id, perr
case reply == "EXPECTED_CRLF\r\n":
return 0, errExpectedCrlf
case reply == "JOB_TOO_BIG\r\n":
return 0, errJobTooBig
case reply == "DRAINING\r\n":
return 0, errDraining
default:
return 0, this.parseError(reply)
}
}
开发者ID:mpdroog,项目名称:smtpw,代码行数:83,代码来源:client.go
示例4: BlockStorageFactory
func BlockStorageFactory(opts map[string]string) (res Storage, err error) {
op := &BlockStorageOptions{"data", 2, 32, 32}
var ok bool
var tmp string
if tmp, ok = opts["root"]; ok {
op.Root = tmp
}
if tmp, ok = opts["split"]; ok {
if _, err = fmt.Sscanf(tmp, "%d", op.Split); err != nil {
return
}
}
if tmp, ok = opts["max-files"]; ok {
if _, err = fmt.Sscanf(tmp, "%d", op.MaxFiles); err != nil {
return
}
}
if tmp, ok = opts["pool"]; ok {
if _, err = fmt.Sscanf(tmp, "%d", op.PoolSize); err != nil {
return
}
}
res = NewBlockStorage(op)
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:27,代码来源:block.go
示例5: MyParseCallback
// Example custom option callback
func MyParseCallback(spec *options.OptionSpec, option string, argument *string) {
if argument != nil {
switch spec.GetCanonical(option) {
case "input-encoding":
in = *argument
case "output-encoding":
out = *argument
case "repeat":
fmt.Sscanf(*argument, "%d", &r)
case "cookie-chance":
fmt.Sscanf(*argument, "%f", &c)
cInt = int64(c * 1000)
default:
spec.PrintUsageAndExit("Unknown option: " + option)
}
} else {
switch spec.GetCanonical(option) {
case "number":
n = true
case "escape":
e = true
case "verbose":
v++
default:
if option == "help" {
spec.PrintUsageAndExit("") // No error
} else {
spec.PrintUsageAndExit("Unknown option: " + option)
}
}
}
}
开发者ID:elasticdog,项目名称:go-options,代码行数:33,代码来源:cat2.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng