本文整理匯總了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))
}
示例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
}
示例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)*/
}
}
示例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)
}
示例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)
}
示例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
}
示例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()
}
示例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>"))
}
示例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")
}
示例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":""}`)
}
示例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
}
示例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"))
}
示例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
}
示例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
}
示例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)
}