本文整理匯總了Golang中fmt.Fprintf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fprintf函數的具體用法?Golang Fprintf怎麽用?Golang Fprintf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fprintf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: xmlToSocketLogWriter
func xmlToSocketLogWriter(filename string, props []xmlProperty, enabled bool) (SocketLogWriter, bool) {
endpoint := ""
protocol := "udp"
for _, prop := range props {
switch prop.Name {
case "endpoint":
endpoint = strings.Trim(prop.Value, " \r\n")
case "protocol":
protocol = strings.Trim(prop.Value, " \r\n")
default:
fmt.Fprintf(os.Stderr, "LoadConfiguration: Warning: Unknown property \"%s\" for file filter in %s\n", prop.Name, filename)
}
}
if len(endpoint) == 0 {
fmt.Fprintf(os.Stderr, "LoadConfiguration: Error: Required property \"%s\" for file filter missing in %s\n", "endpoint", filename)
return nil, false
}
if !enabled {
return nil, true
}
return NewSocketLogWriter(protocol, endpoint), true
}
示例2: identityConfig
// identityConfig initializes a new identity.
func identityConfig(out io.Writer, nbits int) (Identity, error) {
// TODO guard higher up
ident := Identity{}
if nbits < 1024 {
return ident, errors.New("Bitsize less than 1024 is considered unsafe.")
}
fmt.Fprintf(out, "generating %v-bit RSA keypair...", nbits)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits)
if err != nil {
return ident, err
}
fmt.Fprintf(out, "done\n")
// currently storing key unencrypted. in the future we need to encrypt it.
// TODO(security)
skbytes, err := sk.Bytes()
if err != nil {
return ident, err
}
ident.PrivKey = base64.StdEncoding.EncodeToString(skbytes)
id, err := peer.IDFromPublicKey(pk)
if err != nil {
return ident, err
}
ident.PeerID = id.Pretty()
fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID)
return ident, nil
}
示例3: printText
func (p *Addr) printText(w io.Writer, codeblockEnd int) {
switch p.Type {
case None:
case Reg, Xmm:
name := p.Value.(Register).String()
io.WriteString(w, name)
case Ind:
name := p.Value.(Register).String()
if p.Disp != 0 {
fmt.Fprintf(w, "%x+(%s)", p.Disp, name)
} else {
fmt.Fprintf(w, "(%s)", name)
}
case Rel8, Rel16, Rel32:
if codeblockEnd != 0 {
// We know where we are, print the absolute jump point.
blk := int64(codeblockEnd) + p.valueInt64()
fmt.Fprintf(w, "%s:(%06x)", p.Name, blk)
} else {
fmt.Fprintf(w, "%s:(%x)", p.Name, p.Value)
}
case Imm8, Imm16, Imm32, Imm64:
fmt.Fprintf(w, "0x%x", p.Value)
case Label:
fmt.Fprint(w, p.Name)
default:
panic(fmt.Sprintf("unknown addr type: %v", p.Type))
}
}
示例4: check_fatal
func check_fatal(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "**** KURWA!!! ****\n")
fmt.Fprintf(os.Stderr, "Error encountered was of FATAL. Is of wrong. Gib correct config pl0x.\n")
panic(err)
}
}
示例5: postscript
func postscript(out *bytes.Buffer, name string) {
fmt.Fprintf(out, "__start_%s()\n", name)
fmt.Fprintf(out, `{
local cur prev words cword split
_init_completion -s || return
local completions_func
local c=0
local flags=()
local two_word_flags=()
local flags_with_completion=()
local flags_completion=()
local commands=("%s")
local must_have_one_flag=()
local must_have_one_noun=()
local last_command
local nouns=()
__handle_word
}
`, name)
fmt.Fprintf(out, "complete -F __start_%s %s\n", name, name)
fmt.Fprintf(out, "# ex: ts=4 sw=4 et filetype=sh\n")
}
示例6: Execute
func (f *FingerClient) Execute() error {
f.finger.Start()
defer f.finger.Stop()
resp := new(Response)
Logger.Debugf("Executing finger %s", f.Path)
methodName := "Finger.Execute"
if f.args.Flags.Help {
methodName = "Finger.Help"
}
if err := f.finger.Call(methodName, f.args, &resp); err != nil {
Logger.Debugf(resp.SprintLog())
return err
}
stdout := resp.SprintStdout()
stderr := resp.SprintStderr()
fingerLog := resp.SprintLog()
if stdout != "" {
fmt.Println(stdout)
}
if stderr != "" {
fmt.Fprintf(os.Stderr, stderr+"\n")
}
if fingerLog != "" {
fmt.Fprintf(os.Stderr, fingerLog+"\n")
}
return nil
}
示例7: urlShortenerMain
func urlShortenerMain(client *http.Client, argv []string) {
if len(argv) != 1 {
fmt.Fprintf(os.Stderr, "Usage: urlshortener http://goo.gl/xxxxx (to look up details)\n")
fmt.Fprintf(os.Stderr, " urlshortener http://example.com/long (to shorten)\n")
return
}
svc, _ := urlshortener.New(client)
urlstr := argv[0]
// short -> long
if strings.HasPrefix(urlstr, "http://goo.gl/") || strings.HasPrefix(urlstr, "https://goo.gl/") {
url, err := svc.Url.Get(urlstr).Do()
if err != nil {
log.Fatalf("URL Get: %v", err)
}
fmt.Printf("Lookup of %s: %s\n", urlstr, url.LongUrl)
return
}
// long -> short
url, err := svc.Url.Insert(&urlshortener.Url{
Kind: "urlshortener#url", // Not really needed
LongUrl: urlstr,
}).Do()
if err != nil {
log.Fatalf("URL Insert: %v", err)
}
fmt.Printf("Shortened %s => %s\n", urlstr, url.Id)
}
示例8: describeObjects
// describeObjects prints out information about the objects of a template
func (d *TemplateDescriber) describeObjects(objects []runtime.Object, out *tabwriter.Writer) {
formatString(out, "Objects", " ")
indent := " "
for _, obj := range objects {
if d.ObjectDescriber != nil {
output, err := d.DescribeObject(obj)
if err != nil {
fmt.Fprintf(out, "error: %v\n", err)
continue
}
fmt.Fprint(out, output)
fmt.Fprint(out, "\n")
continue
}
_, kind, _ := d.ObjectTyper.ObjectVersionAndKind(obj)
meta := kapi.ObjectMeta{}
meta.Name, _ = d.MetadataAccessor.Name(obj)
fmt.Fprintf(out, fmt.Sprintf("%s%s\t%s\n", indent, kind, meta.Name))
//meta.Annotations, _ = d.MetadataAccessor.Annotations(obj)
//meta.Labels, _ = d.MetadataAccessor.Labels(obj)
/*if len(meta.Labels) > 0 {
formatString(out, indent+"Labels", formatLabels(meta.Labels))
}
formatAnnotations(out, meta, indent)*/
}
}
示例9: drawFittedTableQLetters
//line fitted_type.got:17
func drawFittedTableQLetters(rSeq, qSeq alphabet.QLetters, index alphabet.Index, table []int, a [][]int) {
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ', tabwriter.AlignRight|tabwriter.Debug)
fmt.Printf("rSeq: %s\n", rSeq)
fmt.Printf("qSeq: %s\n", qSeq)
fmt.Fprint(tw, "\tqSeq\t")
for _, l := range qSeq {
fmt.Fprintf(tw, "%c\t", l)
}
fmt.Fprintln(tw)
r, c := rSeq.Len()+1, qSeq.Len()+1
fmt.Fprint(tw, "rSeq\t")
for i := 0; i < r; i++ {
if i != 0 {
fmt.Fprintf(tw, "%c\t", rSeq[i-1].L)
}
for j := 0; j < c; j++ {
p := pointerFittedQLetters(rSeq, qSeq, i, j, table, index, a, c)
if p != "" {
fmt.Fprintf(tw, "%s % 3v\t", p, table[i*c+j])
} else {
fmt.Fprintf(tw, "%v\t", table[i*c+j])
}
}
fmt.Fprintln(tw)
}
tw.Flush()
}
示例10: writeSingle
// Single mode writes a single condensed line. Used for debugging comparison with tester/tester.
func (p *props) writeSingle(w io.Writer) {
fmt.Fprintf(w, `"0","0","1","%d","0","%s",`, p.ftype, escape(p.fname))
fmt.Fprintf(w, `"%x","%x",`, p.ident, p.dident)
fmt.Fprintf(w, `"%s","%s","%s",`, p.ext, p.mime, escape(p.bname))
fmt.Fprintf(w, `"%x",`, p.chash)
fmt.Fprintf(w, "\"%d\",\"%d\",\"%d\"\n", p.size, p.isize.X, p.isize.Y)
}
示例11: Run
func (c *AppRemove) Run(context *cmd.Context, client cmd.Doer) error {
appName, err := c.Guess()
if err != nil {
return err
}
var answer string
if !*tsuru.AssumeYes {
fmt.Fprintf(context.Stdout, `Are you sure you want to remove app "%s"? (y/n) `, appName)
fmt.Fscanf(context.Stdin, "%s", &answer)
if answer != "y" {
fmt.Fprintln(context.Stdout, "Abort.")
return nil
}
}
url := cmd.GetUrl(fmt.Sprintf("/apps/%s", appName))
request, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
_, err = client.Do(request)
if err != nil {
return err
}
fmt.Fprintf(context.Stdout, `App "%s" successfully removed!`+"\n", appName)
return nil
}
示例12: Load
// Load loads the source into the config defined by struct s
func (f *FlagLoader) Load(s interface{}) error {
strct := structs.New(s)
structName := strct.Name()
flagSet := flag.NewFlagSet(structName, flag.ExitOnError)
f.flagSet = flagSet
for _, field := range strct.Fields() {
f.processField(field.Name(), field)
}
flagSet.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flagSet.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nGenerated environment variables:\n")
e := &EnvironmentLoader{
Prefix: f.EnvPrefix,
CamelCase: f.CamelCase,
}
e.PrintEnvs(s)
fmt.Println("")
}
args := os.Args[1:]
if f.Args != nil {
args = f.Args
}
return flagSet.Parse(args)
}
示例13: mkzcgo
// mkzcgo writes zcgo.go for the go/build package:
//
// package build
// var cgoEnabled = map[string]bool{}
//
// It is invoked to write go/build/zcgo.go.
func mkzcgo(dir, file string) {
// sort for deterministic zcgo.go file
var list []string
for plat, hasCgo := range cgoEnabled {
if hasCgo {
list = append(list, plat)
}
}
sort.Strings(list)
var buf bytes.Buffer
fmt.Fprintf(&buf,
"// auto generated by go tool dist\n"+
"\n"+
"package build\n"+
"\n"+
"var cgoEnabled = map[string]bool{\n")
for _, plat := range list {
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
}
fmt.Fprintf(&buf, "}")
writefile(buf.String(), file, writeSkipSame)
}
示例14: ExampleNewDNSInfoProvider
// Create a new DNS info provider.
func ExampleNewDNSInfoProvider() {
// create a DNS client
credentials := APICredentials{"[email protected]", "ApItOken"}
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
os.Exit(1)
}
// create a new DNS info provider instance
dnsInfoProvider := NewDNSInfoProvider(dnsClient)
// get all domain names
domainNames, domainNamesError := dnsInfoProvider.GetDomainNames()
if domainNamesError != nil {
fmt.Fprintf(os.Stderr, "Unable to fetch domain names: %s", domainNamesError.Error())
os.Exit(1)
}
// print a list all domain names
for _, domainName := range domainNames {
fmt.Fprintf(os.Stdout, "%s\n", domainName)
}
}
示例15: verifyCertWithSystem
func verifyCertWithSystem(block *pem.Block, add func(*Certificate)) {
data := pem.EncodeToMemory(block)
var cmd *exec.Cmd
if needsTmpFiles() {
f, err := ioutil.TempFile("", "cert")
if err != nil {
fmt.Fprintf(os.Stderr, "can't create temporary file for cert: %v", err)
return
}
defer os.Remove(f.Name())
if _, err := f.Write(data); err != nil {
fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
return
}
if err := f.Close(); err != nil {
fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
return
}
cmd = exec.Command("/usr/bin/security", "verify-cert", "-c", f.Name(), "-l")
} else {
cmd = exec.Command("/usr/bin/security", "verify-cert", "-c", "/dev/stdin", "-l")
cmd.Stdin = bytes.NewReader(data)
}
if cmd.Run() == nil {
// Non-zero exit means untrusted
cert, err := ParseCertificate(block.Bytes)
if err != nil {
return
}
add(cert)
}
}