当前位置: 首页>>代码示例>>Golang>>正文


Golang fmt.Fprint函数代码示例

本文整理汇总了Golang中fmt.Fprint函数的典型用法代码示例。如果您正苦于以下问题:Golang Fprint函数的具体用法?Golang Fprint怎么用?Golang Fprint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Fprint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetPod

// list specific pod details
func GetPod(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	// node name from user.
	podName := vars["podName"]
	fmt.Fprint(w, string(podName))
	// to do need to read api and port of api server from configuration file
	// TODO: change namespace to flexible.
	var dat map[string]interface{}
	res, err := http.Get(thoth.KubeApi + "/api/v1/namespaces/default/pods/" + podName)
	if err != nil {
		panic(err)
	}
	body, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		panic(err)
	}
	if err := json.Unmarshal(body, &dat); err != nil {
		panic(err)
	}
	pretty_body, err := json.MarshalIndent(dat, "", "  ")
	if err != nil {
		panic(err)
	}
	fmt.Fprint(w, string(pretty_body))
}
开发者ID:SOUP-CE-KMITL,项目名称:Thoth,代码行数:27,代码来源:handler.go

示例2: Encode

// Encode transforms a Tag into a plumbing.EncodedObject.
func (t *Tag) Encode(o plumbing.EncodedObject) error {
	o.SetType(plumbing.TagObject)
	w, err := o.Writer()
	if err != nil {
		return err
	}
	defer ioutil.CheckClose(w, &err)

	if _, err = fmt.Fprintf(w,
		"object %s\ntype %s\ntag %s\ntagger ",
		t.Target.String(), t.TargetType.Bytes(), t.Name); err != nil {
		return err
	}

	if err = t.Tagger.Encode(w); err != nil {
		return err
	}

	if _, err = fmt.Fprint(w, "\n\n"); err != nil {
		return err
	}

	if _, err = fmt.Fprint(w, t.Message); err != nil {
		return err
	}

	return err
}
开发者ID:src-d,项目名称:go-git,代码行数:29,代码来源:tag.go

示例3: 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)*/
	}
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:28,代码来源:describer.go

示例4: newRow

func newRow(w io.Writer, row string, first bool) {
	if !first {
		fmt.Fprint(w, "  </tr>\n")
	}
	fmt.Fprint(w, "  <tr>\n")
	fmt.Fprintf(w, "    <td>%s:</td>\n", row)
}
开发者ID:keep94,项目名称:Dominator,代码行数:7,代码来源:showSubs.go

示例5: AddFileHandler

// AddFileHandler adds the file path to the database. It should be usually be given to an POST endpoint
// with id as the parameter
// Ex: /file/:id
func AddFileHandler(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	decoder := json.NewDecoder(r.Body)
	// TODO: ps is there for checking emptiness. Should be replaced
	var js, ps jsonStruct
	if err := decoder.Decode(&js); err != nil || js == ps {
		w.WriteHeader(400)
		return
	}

	couchServer, err := couchdb.NewClient("http://127.0.0.1:5984", nil)
	db, _ := couchServer.CreateDB("files")
	userID := memberlist.DefaultWANConfig().Name

	_, err = db.Put(p.ByName("id"), file{UUID: uuid.NewV4().String(), Fname: path.Base(js.Path), UserID: userID}, "")
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprint(w, err)
		return
	}

	// TODO: Send 409 for conflict
	if err := AddFile(p.ByName("id"), js.Path); err != nil {
		w.WriteHeader(500)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(201)
}
开发者ID:Gouthamve,项目名称:fshare,代码行数:32,代码来源:fhandlers.1.go

示例6: NewSocketLogWriter

func NewSocketLogWriter(proto, hostport string) SocketLogWriter {
	sock, err := net.Dial(proto, hostport)
	if err != nil {
		fmt.Fprintf(os.Stderr, "NewSocketLogWriter(%q): %s\n", hostport, err)
		return nil
	}

	w := SocketLogWriter(make(chan *LogRecord, LogBufferLength))

	go func() {
		defer func() {
			if sock != nil && proto == "tcp" {
				sock.Close()
			}
		}()

		for rec := range w {
			// Marshall into JSON
			js, err := json.Marshal(rec)
			if err != nil {
				fmt.Fprint(os.Stderr, "SocketLogWriter(%q): %s", hostport, err)
				return
			}

			_, err = sock.Write(js)
			if err != nil {
				fmt.Fprint(os.Stderr, "SocketLogWriter(%q): %s", hostport, err)
				return
			}
		}
	}()

	return w
}
开发者ID:v-gu,项目名称:mysqltc,代码行数:34,代码来源:socklog.go

示例7: 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()
}
开发者ID:krieg,项目名称:biogo,代码行数:30,代码来源:fitted_qletters.go

示例8: xml_txw4i

func xml_txw4i(w http.ResponseWriter, r *http.Request) {
	if !ipchecker(r) {
		return
	}

	w.Header()["Content-Type"] = []string{"text/xml"}
	w.Write([]byte("<pending>"))
	network.TxMutex.Lock()
	for _, v := range network.WaitingForInputs {
		w.Write([]byte("<wait4>"))
		fmt.Fprint(w, "<id>", v.TxID.String(), "</id>")
		for x, t := range v.Ids {
			w.Write([]byte("<tx>"))
			if v, ok := network.TransactionsRejected[x]; ok {
				fmt.Fprint(w, "<id>", v.Id.String(), "</id>")
				fmt.Fprint(w, "<time>", t.Unix(), "</time>")
			} else {
				fmt.Fprint(w, "<id>FATAL ERROR!!! This should not happen! Please report</id>")
				fmt.Fprint(w, "<time>", time.Now().Unix(), "</time>")
			}
			w.Write([]byte("</tx>"))
		}
		w.Write([]byte("</wait4>"))
	}
	network.TxMutex.Unlock()
	w.Write([]byte("</pending>"))
}
开发者ID:Bitoy,项目名称:gocoin,代码行数:27,代码来源:transactions.go

示例9: render

func render(w io.Writer, l *layout.Layout, wires []*layout.Wire, fps map[string]*footprint.Footprint, flip bool) {
	minX := l.MinX - 1
	minY := l.MinY - 1
	maxX := l.MaxX + 1
	maxY := l.MaxY + 1

	innerWidth := maxX - minX
	innerHeight := maxY - minY

	outerHeight := 600
	outerWidth := (outerHeight * innerWidth) / innerHeight

	fmt.Fprint(w, "<?xml version='1.0' standalone='no'?>\n")
	fmt.Fprint(w, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n")
	fmt.Fprintf(w, "<svg width='%d' height='%d' viewBox='%d %d %d %d' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n", outerWidth, outerHeight, minX, minY, innerWidth, innerHeight)
	//fmt.Fprintf(w, "  <rect x='%d' y='%d' width='%d' height='%d' stroke='#999900' stroke-width='0.1' fill='none'/>\n", minX, minY, innerWidth, innerHeight)

	if flip {
		fmt.Fprintf(w, "<g transform='matrix(-1 0 0 1 %d 0)'>\n", innerWidth+minX*2)
	}

	renderGraphics(w, l)
	renderComponents(w, l, fps)
	renderWires(w, l, wires, fps)

	if flip {
		fmt.Fprint(w, "</g>\n")
	}

	fmt.Fprint(w, "</svg>\n")
}
开发者ID:kierdavis,项目名称:k12,代码行数:31,代码来源:render.go

示例10: ModifyProjectHandler

// 修改项目
// uri: /project/modify{json:(|.json)}
func ModifyProjectHandler(rw http.ResponseWriter, req *http.Request) {
	id := req.FormValue("id")
	if id == "" {
		util.Redirect(rw, req, "/projects")
		return
	}

	vars := mux.Vars(req)
	// 请求编辑项目页面
	if req.Method != "POST" || vars["json"] == "" {
		project := service.FindProject(id)
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/new.html")
		filter.SetData(req, map[string]interface{}{"project": project, "activeProjects": "active"})
		return
	}

	user, _ := filter.CurrentUser(req)
	err := service.PublishProject(user, req.PostForm)
	if err != nil {
		if err == service.NotModifyAuthorityErr {
			rw.WriteHeader(http.StatusForbidden)
			return
		}
		fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
		return
	}
	fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:project.go

示例11: printValues

// printValues neatly prints the values returned from execution, followed by a newline.
// It also handles the ')debug types' output.
// The return value reports whether it printed anything.
func printValues(conf *config.Config, writer io.Writer, values []value.Value) bool {
	if len(values) == 0 {
		return false
	}
	if conf.Debug("types") {
		for i, v := range values {
			if i > 0 {
				fmt.Fprint(writer, ",")
			}
			fmt.Fprintf(writer, "%T", v)
		}
		fmt.Fprintln(writer)
	}
	printed := false
	for _, v := range values {
		if _, ok := v.(parse.Assignment); ok {
			continue
		}
		s := v.Sprint(conf)
		if printed && len(s) > 0 && s[len(s)-1] != '\n' {
			fmt.Fprint(writer, " ")
		}
		fmt.Fprint(writer, s)
		printed = true
	}
	if printed {
		fmt.Fprintln(writer)
	}
	return printed
}
开发者ID:db47h,项目名称:ivy,代码行数:33,代码来源:run.go

示例12: TestContention

func (s *metricFileSuite) TestContention(c *gc.C) {
	fileName := filepath.Join(s.spoolDir, "foo")
	mf1, err := createMetricFile(fileName)
	c.Assert(err, gc.IsNil)
	mf2, err := createMetricFile(fileName)
	c.Assert(err, gc.IsNil)

	_, err = fmt.Fprint(mf1, "emacs")
	c.Assert(err, gc.IsNil)
	_, err = fmt.Fprint(mf2, "vi")
	c.Assert(err, gc.IsNil)

	_, err = os.Stat(fileName)
	c.Assert(os.IsNotExist(err), jc.IsTrue)

	err = mf2.Close()
	c.Assert(err, gc.IsNil)
	err = mf1.Close()
	c.Assert(err, gc.NotNil)

	st, err := os.Stat(fileName)
	c.Assert(err, gc.IsNil)
	c.Assert(st.Size(), gc.Equals, int64(2))
	contents, err := ioutil.ReadFile(fileName)
	c.Assert(err, gc.IsNil)
	c.Assert(contents, gc.DeepEquals, []byte("vi"))
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:27,代码来源:metrics_file_test.go

示例13: writeStruct

func writeStruct(w io.Writer, val *reflect.StructValue) (err os.Error) {
	if _, err = fmt.Fprint(w, "{"); err != nil {
		return
	}

	typ := val.Type().(*reflect.StructType)

	for i := 0; i < val.NumField(); i++ {
		fieldValue := val.Field(i)
		if _, err = fmt.Fprintf(w, "%s:", Quote(typ.Field(i).Name)); err != nil {
			return
		}
		if err = writeValue(w, fieldValue); err != nil {
			return
		}
		if i < val.NumField()-1 {
			if _, err = fmt.Fprint(w, ","); err != nil {
				return
			}
		}
	}

	_, err = fmt.Fprint(w, "}")
	return
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:25,代码来源:struct.go

示例14: writeMap

func writeMap(w io.Writer, val *reflect.MapValue) (err os.Error) {
	key := val.Type().(*reflect.MapType).Key()
	if _, ok := key.(*reflect.StringType); !ok {
		return &MarshalError{val.Type()}
	}

	keys := val.Keys()
	if _, err = fmt.Fprint(w, "{"); err != nil {
		return
	}

	for i := 0; i < len(keys); i++ {
		if _, err = fmt.Fprintf(w, "%s:", Quote(keys[i].(*reflect.StringValue).Get())); err != nil {
			return
		}

		if err = writeValue(w, val.Elem(keys[i])); err != nil {
			return
		}

		if i < len(keys)-1 {
			if _, err = fmt.Fprint(w, ","); err != nil {
				return
			}
		}
	}

	_, err = fmt.Fprint(w, "}")
	return
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:30,代码来源:struct.go

示例15: resourcePostgreSQLExtensionCreate

func resourcePostgreSQLExtensionCreate(d *schema.ResourceData, meta interface{}) error {
	c := meta.(*Client)
	c.catalogLock.Lock()
	defer c.catalogLock.Unlock()

	conn, err := c.Connect()
	if err != nil {
		return err
	}
	defer conn.Close()

	extName := d.Get(extNameAttr).(string)

	b := bytes.NewBufferString("CREATE EXTENSION ")
	fmt.Fprint(b, pq.QuoteIdentifier(extName))

	if v, ok := d.GetOk(extSchemaAttr); ok {
		fmt.Fprint(b, " SCHEMA ", pq.QuoteIdentifier(v.(string)))
	}

	if v, ok := d.GetOk(extVersionAttr); ok {
		fmt.Fprint(b, " VERSION ", pq.QuoteIdentifier(v.(string)))
	}

	query := b.String()
	_, err = conn.Query(query)
	if err != nil {
		return errwrap.Wrapf("Error creating extension: {{err}}", err)
	}

	d.SetId(extName)

	return resourcePostgreSQLExtensionReadImpl(d, meta)
}
开发者ID:hashicorp,项目名称:terraform,代码行数:34,代码来源:resource_postgresql_extension.go


注:本文中的fmt.Fprint函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。