本文整理匯總了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)
}
}
示例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())
//.........這裏部分代碼省略.........