當前位置: 首頁>>代碼示例>>Golang>>正文


Golang StickyReader.ReadInt32方法代碼示例

本文整理匯總了Golang中github.com/MJKWoolnough/byteio.StickyReader.ReadInt32方法的典型用法代碼示例。如果您正苦於以下問題:Golang StickyReader.ReadInt32方法的具體用法?Golang StickyReader.ReadInt32怎麽用?Golang StickyReader.ReadInt32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/MJKWoolnough/byteio.StickyReader的用法示例。


在下文中一共展示了StickyReader.ReadInt32方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handle

func (c Console) handle(r *byteio.StickyReader, w *byteio.StickyWriter) error {
	id := int(r.ReadInt32())
	if r.Err != nil {
		return r.Err
	}
	s := c.c.c.Server(id)
	if s == nil {
		return ErrUnknownServer
	}
	s.RLock() //Needed? Path never gets changed!
	p := s.Path
	s.RUnlock()

	var (
		f       *os.File
		err     error
		logPath string
	)

	for _, lp := range logPaths {
		logPath = path.Join(p, lp)
		f, err = os.Open(logPath)
		if err == nil {
			break
		}
	}
	if f == nil {
		return errors.New("unable to open log file")
	}
	defer func() {
		f.Close()
	}()

	fsw, err := fsnotify.NewWatcher()
	if err != nil {
		return err
	}
	logDir := path.Dir(logPath)
	fsw.Add(logDir)
	defer fsw.Remove(logDir)

	pw := partWriter{w}

	io.Copy(pw, f)

	if w.Err != nil {
		return w.Err
	}
	t := time.NewTimer(time.Second * 10)
	for {
		select {
		case ev := <-fsw.Events:
			switch ev.Op {
			case fsnotify.Create:
				if ev.Name == logPath {
					f, err = os.Open(logPath)
					if err != nil {
						return err
					}
				}
			case fsnotify.Write:
				if ev.Name == logPath {
					io.Copy(pw, f)
					if w.Err != nil {
						return w.Err
					}
				}
			case fsnotify.Remove:
				if ev.Name == logPath {
					f.Close()
				}
			}
		case err = <-fsw.Errors:
		case <-t.C:
			w.WriteUint8(2) //ping
			if w.Err != nil {
				return w.Err
			}
		}
		t.Reset(time.Second * 10)
	}
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:82,代碼來源:console.go

示例2: transferFile

func transferFile(typeName, method string, typeID uint8, o *overlay.Overlay) dom.Node {
	name := xform.InputText("name", "")
	url := xform.InputRadio("url", "switch", true)
	upload := xform.InputRadio("upload", "switch", false)
	fileI := xform.InputUpload("")
	urlI := xform.InputURL("", "")
	s := xform.InputSubmit(method)

	name.Required = true

	typeFunc := func(dom.Event) {
		if url.Checked {
			urlI.Style().RemoveProperty("display")
			fileI.Style().SetProperty("display", "none", "")
			urlI.Required = true
			fileI.Required = false
			fileI.SetID("")
			urlI.SetID("file")
		} else {
			fileI.Style().RemoveProperty("display")
			urlI.Style().SetProperty("display", "none", "")
			fileI.Required = true
			urlI.Required = false
			urlI.SetID("")
			fileI.SetID("file")
		}
	}

	typeFunc(nil)

	url.AddEventListener("change", false, typeFunc)
	upload.AddEventListener("change", false, typeFunc)

	f := xjs.AppendChildren(xdom.Form(), xjs.AppendChildren(xdom.Fieldset(),
		xjs.SetInnerText(xdom.Legend(), method+" "+typeName),
		xform.Label(typeName+" Name", "name"),
		name,
		xdom.Br(),

		xform.Label("URL", "url"),
		url,
		xdom.Br(),

		xform.Label("Upload", "upload"),
		upload,
		xdom.Br(),

		xform.Label("File", "file"),

		fileI,
		urlI,

		xdom.Br(),
		s,
	))

	s.AddEventListener("click", false, func(e dom.Event) {
		if name.Value == "" {
			return
		}
		if url.Checked {
			if urlI.Value == "" {
				return
			}
		} else if len(fileI.Files()) != 1 {
			return

		}
		s.Disabled = true
		name.Disabled = true
		url.Disabled = true
		upload.Disabled = true
		fileI.Disabled = true
		urlI.Disabled = true
		e.PreventDefault()
		go func() {
			d := xdom.Div()
			uo := overlay.New(d)
			uo.OnClose(func() {
				o.Close()
			})
			xjs.Body().AppendChild(uo)
			status := xdom.Div()
			d.AppendChild(xjs.SetInnerText(status, "Transferring..."))
			conn, err := websocket.Dial("ws://" + js.Global.Get("location").Get("host").String() + "/transfer")
			if err != nil {
				xjs.SetInnerText(status, err.Error())
				return
			}
			defer conn.Close()
			w := byteio.StickyWriter{Writer: byteio.LittleEndianWriter{Writer: conn}}
			r := byteio.StickyReader{Reader: byteio.LittleEndianReader{Reader: conn}}

			pb := progress.New(color.RGBA{255, 0, 0, 0}, color.RGBA{0, 0, 255, 0}, 400, 50)
			d.AppendChild(pb)

			if url.Checked {
				w.WriteUint8(typeID << 1)
				data.WriteString(&w, urlI.Value)
				length := int(r.ReadInt32())
//.........這裏部分代碼省略.........
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:101,代碼來源:utils.go


注:本文中的github.com/MJKWoolnough/byteio.StickyReader.ReadInt32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。