本文整理汇总了Golang中fmt.Fprintln函数的典型用法代码示例。如果您正苦于以下问题:Golang Fprintln函数的具体用法?Golang Fprintln怎么用?Golang Fprintln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fprintln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Create
// Create three folders for each id
// mnt, layers, and diff
func (a *Driver) Create(id, parent, mountLabel string, storageOpt map[string]string) error {
if len(storageOpt) != 0 {
return fmt.Errorf("--storage-opt is not supported for aufs")
}
if err := a.createDirsFor(id); err != nil {
return err
}
// Write the layers metadata
f, err := os.Create(path.Join(a.rootPath(), "layers", id))
if err != nil {
return err
}
defer f.Close()
if parent != "" {
ids, err := getParentIds(a.rootPath(), parent)
if err != nil {
return err
}
if _, err := fmt.Fprintln(f, parent); err != nil {
return err
}
for _, i := range ids {
if _, err := fmt.Fprintln(f, i); err != nil {
return err
}
}
}
return nil
}
示例2: 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()
}
示例3: printColors
func printColors() {
ansi.DisableColors(false)
stdout := colorable.NewColorableStdout()
bgColors := []string{
"",
":black",
":red",
":green",
":yellow",
":blue",
":magenta",
":cyan",
":white",
}
keys := []string{}
for fg := range ansi.Colors {
_, err := strconv.Atoi(fg)
if err != nil {
keys = append(keys, fg)
}
}
sort.Strings(keys)
for _, fg := range keys {
for _, bg := range bgColors {
fmt.Fprintln(stdout, padColor(fg, []string{"" + bg, "+b" + bg, "+bh" + bg, "+u" + bg}))
fmt.Fprintln(stdout, padColor(fg, []string{"+uh" + bg, "+B" + bg, "+Bb" + bg /* backgrounds */, "" + bg + "+h"}))
fmt.Fprintln(stdout, padColor(fg, []string{"+b" + bg + "+h", "+bh" + bg + "+h", "+u" + bg + "+h", "+uh" + bg + "+h"}))
}
}
}
示例4: TestDisconnectEverythingFromSpecificSlot
func (s *SnapSuite) TestDisconnectEverythingFromSpecificSlot(c *C) {
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/v2/interfaces":
c.Check(r.Method, Equals, "POST")
c.Check(DecodedRequestBody(c, r), DeepEquals, map[string]interface{}{
"action": "disconnect",
"plugs": []interface{}{
map[string]interface{}{
"snap": "",
"plug": "",
},
},
"slots": []interface{}{
map[string]interface{}{
"snap": "consumer",
"slot": "slot",
},
},
})
fmt.Fprintln(w, `{"type":"async", "status-code": 202, "change": "zzz"}`)
case "/v2/changes/zzz":
c.Check(r.Method, Equals, "GET")
fmt.Fprintln(w, `{"type":"sync", "result":{"ready": true, "status": "Done"}}`)
default:
c.Fatalf("unexpected path %q", r.URL.Path)
}
})
rest, err := Parser().ParseArgs([]string{"disconnect", "consumer:slot"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})
c.Assert(s.Stdout(), Equals, "")
c.Assert(s.Stderr(), Equals, "")
}
示例5: printUsageErrorAndExit
func printUsageErrorAndExit(message string) {
fmt.Fprintln(os.Stderr, "ERROR:", message)
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Available command line options:")
flag.PrintDefaults()
os.Exit(64)
}
示例6: actionUserPasswd
func actionUserPasswd(c *cli.Context) {
api, user := mustUserAPIAndName(c)
ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
currentUser, err := api.GetUser(ctx, user)
cancel()
if currentUser == nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
pass, err := speakeasy.Ask("New password: ")
if err != nil {
fmt.Fprintln(os.Stderr, "Error reading password:", err)
os.Exit(1)
}
ctx, cancel = context.WithTimeout(context.Background(), client.DefaultRequestTimeout)
_, err = api.ChangePassword(ctx, user, pass)
cancel()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
fmt.Printf("Password updated\n")
}
示例7: TestGetCSVFailParseSep
func TestGetCSVFailParseSep(t *testing.T) {
defer testRetryWhenDone().Reset()
reqCount := 0
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if reqCount > 0 {
w.Header().Add("Content-type", "application/json")
fmt.Fprintln(w, `gomeetup,city`)
fmt.Fprintln(w, `yes,Sydney`)
fmt.Fprintln(w, `yes,San Francisco`)
fmt.Fprintln(w, `yes,Stockholm`)
} else {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, `ERROR 500`)
}
reqCount++
}))
defer ts.Close()
url := ts.URL + "/test.csv"
defer os.Remove(getCacheFileID(url))
want := [][]string{[]string{"gomeetup", "city"}, []string{"yes", "Sydney"}, []string{"yes", "San Francisco"}, []string{"yes", "Stockholm"}}
have := GetCSV(",", url)
assert.NotNil(t, have)
if have != nil {
assert.EqualValues(t, want, have)
}
}
示例8: enumerate
func (c *clusterClient) enumerate(context *cli.Context) {
c.clusterOptions(context)
jsonOut := context.GlobalBool("json")
outFd := os.Stdout
fn := "enumerate"
cluster, err := c.manager.Enumerate()
if err != nil {
cmdError(context, fn, err)
return
}
if jsonOut {
fmtOutput(context, &Format{Cluster: &cluster})
} else {
w := new(tabwriter.Writer)
w.Init(outFd, 12, 12, 1, ' ', 0)
fmt.Fprintln(w, "ID\t IMAGE\t STATUS\t NAMES\t NODE")
for _, n := range cluster.Nodes {
for _, c := range n.Containers {
fmt.Fprintln(w, c.ID, "\t", c.Image, "\t", c.Status, "\t",
c.Names, "\t", n.Ip)
}
}
fmt.Fprintln(w)
w.Flush()
}
}
示例9: newApp
func newApp(args []string) {
// check for proper args by count
if len(args) == 0 {
errorf("No import path given.\nRun 'revel help new' for usage.\n")
}
if len(args) > 2 {
errorf("Too many arguments provided.\nRun 'revel help new' for usage.\n")
}
// checking and setting go paths
initGoPaths()
// checking and setting application
setApplicationPath(args)
// checking and setting skeleton
setSkeletonPath(args)
// copy files to new app directory
copyNewAppFiles()
// goodbye world
fmt.Fprintln(os.Stdout, "Your application is ready:\n ", appPath)
fmt.Fprintln(os.Stdout, "\nYou can run it with:\n revel run", importPath)
}
示例10: main
func main() {
if len(os.Args) < 4 {
fmt.Fprintln(os.Stderr, "Usage: say-phones <output> <voice>",
"<phones ...>")
os.Exit(1)
}
phones := make([]gospeech.Phone, 0, len(os.Args)-3)
for _, str := range os.Args[3:] {
p, err := gospeech.ParsePhone(str)
if err != nil {
fmt.Fprintln(os.Stderr, "Invalid phone: "+str)
os.Exit(1)
}
phones = append(phones, p)
}
voice, err := gospeech.LoadVoice(os.Args[2])
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to load voice:", err)
os.Exit(1)
}
sound := gospeech.SynthesizePhones(phones, voice)
if err := wav.WriteFile(sound, os.Args[1]); err != nil {
fmt.Fprintln(os.Stderr, "Failed to write output:", err)
os.Exit(1)
}
}
示例11: describeServiceAccount
func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Secret) (string, error) {
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", serviceAccount.Name)
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(serviceAccount.Labels))
if len(serviceAccount.Secrets) == 0 {
fmt.Fprintf(out, "Secrets:\t<none>\n")
} else {
prefix := "Secrets:"
for _, s := range serviceAccount.Secrets {
fmt.Fprintf(out, "%s\t%s\n", prefix, s)
prefix = " "
}
fmt.Fprintln(out)
}
if len(tokens) == 0 {
fmt.Fprintf(out, "Tokens: \t<none>\n")
} else {
prefix := "Tokens: "
for _, t := range tokens {
fmt.Fprintf(out, "%s\t%s\n", prefix, t.Name)
prefix = " "
}
fmt.Fprintln(out)
}
return nil
})
}
示例12: Branch
func Branch(repo *libgit.Repository, args []string) {
switch len(args) {
case 0:
branches, err := repo.GetBranches()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not get list of branches.")
return
}
head := getHeadBranch(repo)
for _, b := range branches {
if head == b {
fmt.Print("* ")
} else {
fmt.Print(" ")
}
fmt.Println(b)
}
case 1:
if head, err := getHeadId(repo); err == nil {
if cerr := libgit.CreateBranch(repo.Path, args[0], head); cerr != nil {
fmt.Fprintf(os.Stderr, "Could not create branch: %s\n", cerr.Error())
}
} else {
fmt.Fprintf(os.Stderr, "Could not create branch: %s\n", err.Error())
}
default:
fmt.Fprintln(os.Stderr, "Usage: go-git branch [branchname]")
}
}
示例13: main
func main() {
var bb bytes.Buffer
fmt.Fprintf(&bb, "// go run gentest.go\n")
fmt.Fprintf(&bb, "// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n")
fmt.Fprintf(&bb, "package ipv6_test\n\n")
for _, r := range registries {
resp, err := http.Get(r.url)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Fprintf(os.Stderr, "got HTTP status code %v for %v\n", resp.StatusCode, r.url)
os.Exit(1)
}
if err := r.parse(&bb, resp.Body); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Fprintf(&bb, "\n")
}
b, err := format.Source(bb.Bytes())
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Stdout.Write(b)
}
示例14: Debug
func (d AsyncGofunge93Debugger) Debug(ip IP) {
inst := d.AsyncGofunge93.code[ip.Dim(1)][ip.Dim(0)];
if d.printCoords {
fmt.Fprintf(os.Stderr, "\n%c (%v, %v)", inst, ip.Dim(0), ip.Dim(1));
}
if d.printStack {
fmt.Fprintf(os.Stderr, "\n%v", d.AsyncGofunge93.stack.v.Data());
}
if d.printTrace {
fmt.Fprint(os.Stderr, "\n");
for i, row := range d.AsyncGofunge93.code {
if int32(i) == ip.Dim(1) {
fmt.Fprint(os.Stderr, string(row[0:ip.Dim(0)]));
fmt.Fprint(os.Stderr, "█");
fmt.Fprintln(os.Stderr, string(row[ip.Dim(0)+1:len(row)]));
}
else {
fmt.Fprintln(os.Stderr, string(row));
}
}
}
if d.pause {
os.Stdin.Read(make([]byte, 1));
}
}
示例15: logSetup
func logSetup() {
level, err := log.LevelInt(*f_loglevel)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
color := true
if runtime.GOOS == "windows" {
color = false
}
if *f_log {
log.AddLogger("stdio", os.Stderr, level, color)
}
if *f_logfile != "" {
err := os.MkdirAll(filepath.Dir(*f_logfile), 0755)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
logfile, err := os.OpenFile(*f_logfile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
log.AddLogger("file", logfile, level, false)
}
}