本文整理汇总了Golang中log.Stderr函数的典型用法代码示例。如果您正苦于以下问题:Golang Stderr函数的具体用法?Golang Stderr怎么用?Golang Stderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stderr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
// Handle the data from a single imported data stream, which will
// have the form
// (response, data)*
// The response identifies by name which channel is receiving data.
// TODO: allow an importer to send.
func (imp *Importer) run() {
// Loop on responses; requests are sent by ImportNValues()
resp := new(response)
for {
if err := imp.decode(resp); err != nil {
log.Stderr("importer response decode:", err)
break
}
if resp.error != "" {
log.Stderr("importer response error:", resp.error)
// TODO: tear down connection
break
}
imp.chanLock.Lock()
ich, ok := imp.chans[resp.name]
imp.chanLock.Unlock()
if !ok {
log.Stderr("unknown name in request:", resp.name)
break
}
if ich.dir != Recv {
log.Stderr("TODO: import send unimplemented")
break
}
// Create a new value for each received item.
val := reflect.MakeZero(ich.ptr.Type().(*reflect.PtrType).Elem())
ich.ptr.PointTo(val)
if err := imp.decode(ich.ptr.Interface()); err != nil {
log.Stderr("importer value decode:", err)
return
}
ich.ch.Send(val)
}
}
示例2: main
func main() {
// create the client. Here we are using a synchronous client.
// Using the default ConnectionSpec, we are specifying the client to connect
// to db 13 (e.g. SELECT 13), and a password of go-redis (e.g. AUTH go-redis)
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
log.Stderr("failed to create the client", e)
return
}
key := "examples/hello/user.name"
value, e := client.Get(key)
if e != nil {
log.Stderr("error on Get", e)
return
}
if value == nil {
fmt.Printf("\nHello, don't believe we've met before!\nYour name? ")
reader := bufio.NewReader(os.Stdin)
user, _ := reader.ReadString(byte('\n'))
if len(user) > 1 {
user = user[0 : len(user)-1]
value = []byte(user)
client.Set(key, value)
} else {
fmt.Printf("vafanculo!\n")
return
}
}
fmt.Printf("Hey, ciao %s!\n", fmt.Sprintf("%s", value))
}
示例3: WriteHeader
// WriteHeader sends an HTTP response header with status code.
// If WriteHeader is not called explicitly, the first call to Write
// will trigger an implicit WriteHeader(http.StatusOK).
// Thus explicit calls to WriteHeader are mainly used to
// send error codes.
func (c *Conn) WriteHeader(code int) {
if c.hijacked {
log.Stderr("http: Conn.WriteHeader on hijacked connection")
return
}
if c.wroteHeader {
log.Stderr("http: multiple Conn.WriteHeader calls")
return
}
c.wroteHeader = true
c.status = code
c.written = 0
if !c.Req.ProtoAtLeast(1, 0) {
return
}
proto := "HTTP/1.0"
if c.Req.ProtoAtLeast(1, 1) {
proto = "HTTP/1.1"
}
codestring := strconv.Itoa(code)
text, ok := statusText[code]
if !ok {
text = "status code " + codestring
}
io.WriteString(c.buf, proto+" "+codestring+" "+text+"\r\n")
for k, v := range c.header {
io.WriteString(c.buf, k+": "+v+"\r\n")
}
io.WriteString(c.buf, "\r\n")
}
示例4: serveRecv
// Send all the data on a single channel to a client asking for a Recv
func (client *expClient) serveRecv(req *request) {
exp := client.exp
resp := new(response)
resp.name = req.name
var ok bool
exp.chanLock.Lock()
ech, ok := exp.chans[req.name]
exp.chanLock.Unlock()
if !ok {
resp.error = "no such channel: " + req.name
log.Stderr("export:", resp.error)
client.encode(resp, nil) // ignore any encode error, hope client gets it
return
}
for {
if ech.dir != Send {
log.Stderr("TODO: recv export unimplemented")
break
}
val := ech.ch.Recv()
if err := client.encode(resp, val.Interface()); err != nil {
log.Stderr("error encoding client response:", err)
break
}
if req.count > 0 {
req.count--
if req.count == 0 {
break
}
}
}
}
示例5: WriteHeader
// WriteHeader sends an HTTP response header with status code.
// If WriteHeader is not called explicitly, the first call to Write
// will trigger an implicit WriteHeader(http.StatusOK).
// Thus explicit calls to WriteHeader are mainly used to
// send error codes.
func (c *Conn) WriteHeader(code int) {
if c.hijacked {
log.Stderr("http: Conn.WriteHeader on hijacked connection")
return
}
if c.wroteHeader {
log.Stderr("http: multiple Conn.WriteHeader calls")
return
}
c.wroteHeader = true
c.status = code
if code == StatusNotModified {
// Must not have body.
c.header["Content-Type"] = "", false
c.header["Transfer-Encoding"] = "", false
}
c.written = 0
if !c.Req.ProtoAtLeast(1, 0) {
return
}
proto := "HTTP/1.0"
if c.Req.ProtoAtLeast(1, 1) {
proto = "HTTP/1.1"
}
codestring := strconv.Itoa(code)
text, ok := statusText[code]
if !ok {
text = "status code " + codestring
}
io.WriteString(c.buf, proto+" "+codestring+" "+text+"\r\n")
for k, v := range c.header {
io.WriteString(c.buf, k+": "+v+"\r\n")
}
io.WriteString(c.buf, "\r\n")
}
示例6: proxyMuxer
func proxyMuxer() {
proxyMap := make(map[string]*proxy)
for {
select {
case pp := <-queue:
key := make([]byte, keyLen)
// read key
n, err := pp.r.Body.Read(key)
if n != keyLen || err != nil {
log.Stderr("Couldn't read key", key)
continue
}
// find proxy
p, ok := proxyMap[string(key)]
if !ok {
log.Stderr("Couldn't find proxy", key)
continue
}
// handle
p.handle(pp)
case p := <-createQueue:
proxyMap[p.key] = p
}
}
}
示例7: serveConnection
func serveConnection(serverName string, secure bool, handler web.Handler, netConn net.Conn) {
br := bufio.NewReader(netConn)
for {
c := conn{
serverName: serverName,
secure: secure,
netConn: netConn,
br: br}
if err := c.prepare(); err != nil {
if err != os.EOF {
log.Stderr("twister/sever: prepare failed", err)
}
break
}
handler.ServeWeb(c.req)
if c.hijacked {
return
}
if err := c.finish(); err != nil {
log.Stderr("twister/sever: finish failed", err)
break
}
if c.closeAfterResponse {
break
}
}
netConn.Close()
}
示例8:
func managementTask (c *asyncConnHdl, ctl workerCtl) (sig *interrupt_code, te *taskStatus) {
/* TODO:
connected:
clearChannels();
startWokers();
disconnected:
?
on_fault:
disconnect();
goto disconnected;
on_exit:
?
*/
log.Stderr("MGR: do task ...");
select {
case stat:= <-c.feedback:
log.Stderr("MGR: Feedback from one of my minions: ", stat);
// do the shutdown for now -- TODO: try reconnect
if stat.event == faulted {
log.Stderr("MGR: Shutting down due to fault in ", stat.id);
go func() { c.reqProcCtl <- stop; } ();
go func() { c.rspProcCtl <- stop; } ();
go func() { c.heartbeatCtl <- stop; } ();
log.Stderr("MGR: Signal SHUTDOWN ... ");
c.shutdown <- true;
// stop self // TODO: should manager really be a task or a FSM?
c.managerCtl <- stop;
}
case s := <- ctl:
return &s, &ok_status;
}
return nil, &ok_status;
}
示例9: run
// Manage sends and receives for a single client. For each (client Recv) request,
// this will launch a serveRecv goroutine to deliver the data for that channel,
// while (client Send) requests are handled as data arrives from the client.
func (client *expClient) run() {
hdr := new(header)
req := new(request)
error := new(error)
for {
if err := client.decode(hdr); err != nil {
log.Stderr("error decoding client header:", err)
// TODO: tear down connection
return
}
switch hdr.payloadType {
case payRequest:
if err := client.decode(req); err != nil {
log.Stderr("error decoding client request:", err)
// TODO: tear down connection
return
}
switch req.dir {
case Recv:
go client.serveRecv(*hdr, req.count)
case Send:
// Request to send is clear as a matter of protocol
// but not actually used by the implementation.
// The actual sends will have payload type payData.
// TODO: manage the count?
default:
error.error = "export request: can't handle channel direction"
log.Stderr(error.error, req.dir)
client.encode(hdr, payError, error)
}
case payData:
client.serveSend(*hdr)
}
}
}
示例10: handleMessage
func handleMessage(s net.Conn, reqChannel chan MCRequest) (ret bool) {
log.Stdoutf("Handling a message...")
hdrBytes := make([]byte, HDR_LEN)
ret = false
log.Stdoutf("Reading header...")
bytesRead, err := io.ReadFull(s, hdrBytes)
if err != nil || bytesRead != HDR_LEN {
log.Stderr("Error reading message: %s (%d bytes)", err, bytesRead)
return
}
req := grokHeader(hdrBytes)
readContents(s, req)
log.Stdout("Processing message %s", req)
req.ResponseChannel = make(chan MCResponse)
reqChannel <- req
res := <-req.ResponseChannel
ret = !res.Fatal
if ret {
log.Stdoutf("Got response %s", res)
transmitResponse(s, req, res)
} else {
log.Stderr("Something went wrong, hanging up...")
}
return
}
示例11: main
func main() {
flag.Parse()
listener, err := net.Listen("tcp", *listenAddr)
if err != nil {
panic(err)
}
conn, err := listener.Accept()
if err != nil {
panic(err)
}
buf := new(bytes.Buffer)
// initiate new session and read key
log.Stderr("Attempting connect", *destAddr)
buf.Write([]byte(*destAddr))
resp, err := http.Post(
"http://"+*httpAddr+"/create",
"text/plain",
buf)
if err != nil {
panic(err)
}
key, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
log.Stderr("Connected, key", key)
// ticker to set a rate at which to hit the server
tick := time.NewTicker(int64(*tickInterval) * 1e6)
read := makeReadChan(conn, bufSize)
buf.Reset()
for {
select {
case <-tick.C:
// write buf to new http request
req := bytes.NewBuffer(key)
buf.WriteTo(req)
resp, err := http.Post(
"http://"+*httpAddr+"/ping",
"application/octet-stream",
req)
if err != nil {
log.Stderr(err.String())
continue
}
// write http response response to conn
io.Copy(conn, resp.Body)
resp.Body.Close()
case b := <-read:
buf.Write(b)
}
}
}
示例12: worker
// This could find a happy home in a generalized worker package ...
// TODO
func (c *asyncConnHdl) worker(id int, name string, task workerTask, ctl workerCtl, fb chan workerStatus) {
var signal interrupt_code
var tstat *taskStatus
// todo: add startup hook for worker
await_signal:
log.Stdout(name, "_worker: await_signal.")
signal = <-ctl
on_interrupt:
// log.Stdout(name, "_worker: on_interrupt: ", signal);
switch signal {
case stop:
goto before_stop
case pause:
goto await_signal
case start:
goto work
}
work:
// log.Stdout(name, "_worker: work!");
select {
case signal = <-ctl:
goto on_interrupt
default:
is, stat := task(c, ctl) // todo is a task context type
if stat == nil {
log.Stderr("<BUG> nil stat from worker ", name)
}
if stat.code != ok {
log.Stdout(name, "_worker: task error!")
tstat = stat
goto on_error
} else if is != nil {
signal = *is
goto on_interrupt
}
goto work
}
on_error:
log.Stdout(name, "_worker: on_error!")
// TODO: log it, send it, and go back to wait_start:
log.Stderr(name, "_worker task raised error: ", tstat)
fb <- workerStatus{id, faulted, tstat, &ctl}
goto await_signal
before_stop:
log.Stdout(name, "_worker: before_stop!")
// TODO: add shutdown hook for worker
log.Stdout(name, "_worker: STOPPED!")
}
示例13: NewProxy
func NewProxy(key, destAddr string) (p *proxy, err os.Error) {
p = &proxy{C: make(chan proxyPacket), key: key}
log.Stderr("Attempting connect", destAddr)
p.conn, err = net.Dial("tcp", "", destAddr)
if err != nil {
return
}
p.conn.SetReadTimeout(readTimeout)
log.Stderr("Connected", destAddr)
return
}
示例14: signalListener
func signalListener(end chan bool) {
for {
if n := <-signal.Incoming; strings.HasPrefix(n.String(), "SIGINT") {
log.Stderr("Received SIGINT, ending execution")
end <- true
return
} else {
log.Stderr("Received singal", n, "ignoring")
}
}
}
示例15: main
func main() {
var m int
var user g9p.User
var file *g9pc.File
flag.Parse()
user = g9p.OsUsers.Uid2User(os.Geteuid())
c, err := g9pc.Mount("tcp", *addr, "", user, nil)
if err != nil {
goto error
}
if flag.NArg() != 1 {
log.Stderr("invalid arguments")
return
}
file, err = c.FOpen(flag.Arg(0), g9p.OWRITE|g9p.OTRUNC)
if err != nil {
file, err = c.FCreate(flag.Arg(0), 0666, g9p.OWRITE)
if err != nil {
goto error
}
}
buf := make([]byte, 8192)
for {
n, oserr := os.Stdin.Read(buf)
if oserr != nil && oserr != io.EOF {
err = &g9p.Error{oserr.String(), 0}
goto error
}
if n == 0 {
break
}
m, err = file.Write(buf[0:n])
if err != nil {
goto error
}
if m != n {
err = &g9p.Error{"short write", 0}
goto error
}
}
file.Close()
return
error:
log.Stderr(fmt.Sprintf("Error: %v", err))
}