本文整理汇总了Golang中log.Stdoutf函数的典型用法代码示例。如果您正苦于以下问题:Golang Stdoutf函数的具体用法?Golang Stdoutf怎么用?Golang Stdoutf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stdoutf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var host *string = flag.String("host", "localhost", "hostname")
var port *int = flag.Int("port", 9999, "port")
flag.Parse()
var ipAddr string = *host + ":" + strconv.Itoa(*port)
log.Stdoutf("host=[%s] port=%d addr=[%s]", *host, *port, ipAddr)
udpAddr, err := net.ResolveUDPAddr(ipAddr)
if udpAddr == nil {
log.Stdoutf("ResolveUDPAddr failed: %s", err.String())
os.Exit(1)
}
udpConn, err := net.ListenUDP("udp", udpAddr)
if udpConn == nil {
log.Stdoutf("ListenUDP failed: %s", err.String())
os.Exit(1)
}
udpConn.SetReadTimeout(10)
stscall.SetNonblock(udpConn.fd, false)
var buff [50]byte
sz, rUdpAddr, err := udpConn.ReadFromUDP(&buff)
if err != nil {
log.Stdoutf("Read failed: %s", err.String())
os.Exit(1)
}
log.Stdoutf("read from remote addr: [%s] sz=%d buff=[%s]", rUdpAddr.String(), sz, buff)
// var udpAddr *net.UDPAddr, err os.Error = net.ResolveUDPAddr(ipAddr);
}
示例2: 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
}
示例3: newIRC
func newIRC(c net.Conn) (irc *IRC) {
irc = &IRC{Reader: make(chan string, 10), Writer: make(chan string, 10)}
// start reader
go func(r *bufio.Reader) {
for {
line, err := r.ReadString('\n')
if err != nil {
log.Exit("Unable to read from channel", err)
}
log.Stdoutf("Read: %#v", line)
irc.Reader <- line
}
}(bufio.NewReader(c))
// start writer
go func(w *bufio.Writer) {
for {
line := <-irc.Writer
_, err := w.WriteString(line)
if err != nil {
log.Exit("Unable to write to channel", err)
}
err = w.Flush()
if err != nil {
log.Exit("Unable to write to channel", err)
}
log.Stdoutf("Wrote: %#v", line)
}
}(bufio.NewWriter(c))
return irc
}
示例4: Write
func (l *writeLogger) Write(p []byte) (n int, err os.Error) {
n, err = l.w.Write(p)
if err != nil {
log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err)
} else {
log.Stdoutf("%s %x", l.prefix, p[0:n])
}
return
}
示例5: Read
func (l *readLogger) Read(p []byte) (n int, err os.Error) {
n, err = l.r.Read(p)
if err != nil {
log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err)
} else {
log.Stdoutf("%s %x", l.prefix, p[0:n])
}
return
}
示例6: GetUserTimeline
/**
* GetUserTimeline gets the user's timeline (provided by screenName) using the credentials
* saved in the Client provided.
*/
func GetUserTimeline(client *Client, screenName string) (statuses []Status, err os.Error) {
log.Stdout("Get User's Timeline\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
// send request
jsonStrResponse, err = send(URLUserTimeline+"?screen_name="+screenName+"&count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
//log.Stdout("response: %s", jsonStrResponse);
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
var elem = resultObj.Elem(i)
//log.Stdoutf("found status: %s\n", elem.Get("text").String());
statuses[i] = *parseStatus(elem)
}
return
}
示例7: GetDirectMessages
/**
* GetDirectMessages gets all of your direct messages. It uses the credentials
* saved in the Client provided.
*/
func GetDirectMessages(client *Client) (statuses []Status, err os.Error) {
log.Stdout("Get Direct Messages\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
// send request
jsonStrResponse, err = send(URLDirectMessages+"?count="+strconv.Itoa(maxFetchCount), "GET", nil, client, "")
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
//log.Stdout("response: %s", jsonStrResponse);
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
statuses[i] = *parseDirectMessage(resultObj.Elem(i))
}
return
}
示例8: GetMentions
/**
* GetMentions gets all mentions of you using the credentials
* saved in the Client provided.
*/
func GetMentions(client *Client) (statuses []Status, err os.Error) {
log.Stdout("Get Mentions\n")
// get json response from server
var jsonStrResponse string
var maxFetchCount = client.MaxFetchCount
if maxFetchCount == 0 {
maxFetchCount = DefaultMaxFetchCount
} // use a default
var form = map[string][]string{
"count": []string{strconv.Itoa(maxFetchCount)},
}
// send request
jsonStrResponse, err = send(URLMentions, "GET", form, client, "count="+strconv.Itoa(maxFetchCount))
if err != nil {
return nil, err
}
// parse json response
var resultObj json.Json
resultObj, err = parseJson(jsonStrResponse)
if err != nil {
return nil, err
}
// create status response
var i int
statuses = make([]Status, resultObj.Len())
log.Stdoutf("result count: %d", resultObj.Len())
for i = 0; i < len(statuses); i++ {
var elem = resultObj.Elem(i)
statuses[i] = *parseStatus(elem)
}
return
}
示例9: NewConsoleLogger
func NewConsoleLogger(logLevel Severity) *ConsoleLogger {
logger := &ConsoleLogger{}
logger.base = &base{}
logger.base.LogLevel = logLevel
logger.base.addFunc = func(severity Severity, format string, v ...interface{}) { log.Stdoutf(format, v) }
return logger
}
示例10: main
func main() {
var address, key string
var count, delay, step int
flag.StringVar(&address, "address", "127.0.0.1:6311", "Set the port (+optional address) to send packets to")
flag.StringVar(&key, "key", "profile", "Set the key name (pakets data will be \"key:idx\")")
flag.IntVar(&count, "count", 1000, "Set the number of packets to send")
flag.IntVar(&delay, "delay", 1000000, "Set the delay between packets in nanoseconds (10^-9)")
flag.IntVar(&step, "step", 100, "Log step (how many packets to send between logging)")
flag.Parse()
udp_address, error := net.ResolveUDPAddr(address)
if error != nil {
log.Exitf("Cannot parse \"%s\": %s", address, error)
}
log.Stdout(udp_address)
ticker := time.NewTicker(int64(delay))
defer ticker.Stop()
for sent := 1; sent <= count; sent++ {
<-ticker.C
send(udp_address, key, sent)
if sent%step == 0 {
log.Stdoutf("Processed %d packets of %d", sent, count)
}
}
}
示例11: HandleUpdateStatus
// handle a request to change the status
func HandleUpdateStatus(c *http.Conn, req *http.Request) {
req.ParseForm()
statusStr := req.FormValue("status")
log.Stdoutf("status to be sent:\n%s\n\n", statusStr)
jsonStr, _ := twitter.TweetJson(&creds, statusStr)
io.WriteString(c, jsonStr)
}
示例12: Process
func (bot *Bot) Process(message *Message, out chan string) {
switch message.Command {
case "PING":
message.Ping(out)
default:
log.Stdoutf("%#v", message)
}
}
示例13: Run
func (s *Server) Run(addr string) {
mux := http.NewServeMux()
mux.Handle("/", s)
log.Stdoutf("web.go serving %s", addr)
err := http.ListenAndServe(addr, mux)
if err != nil {
log.Exit("ListenAndServe:", err)
}
}
示例14: Run
//runs the web application and serves http requests
func Run(addr string) {
http.Handle("/", http.HandlerFunc(httpHandler))
log.Stdoutf("web.go serving %s", addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Exit("ListenAndServe:", err)
}
}
示例15: Call
func (this *action) Call(method string, data interface{}) interface{} {
switch method {
case "hello":
return "Hello world"
case "echo":
v, ok := data.([]interface{})
if !ok {
log.Stdoutf("first echo type assertion not ok")
return nil
}
v2, ok2 := v[0].(map[string]interface{})
if !ok2 {
log.Stdoutf("second echo type assertion not ok")
return nil
}
return v2["message"]
}
return nil
}