当前位置: 首页>>代码示例>>Golang>>正文


Golang log.Stdoutf函数代码示例

本文整理汇总了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);
}
开发者ID:nonstop,项目名称:sandbox,代码行数:29,代码来源:server.go

示例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
}
开发者ID:andradeandrey,项目名称:gomemcached,代码行数:30,代码来源:mc_conn_handler.go

示例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
}
开发者ID:davecheney,项目名称:gobot,代码行数:33,代码来源:irc.go

示例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
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:9,代码来源:logger.go

示例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
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:9,代码来源:logger.go

示例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
}
开发者ID:tommed,项目名称:GoogleGo-Twitter-Client,代码行数:38,代码来源:twitter.go

示例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
}
开发者ID:tommed,项目名称:GoogleGo-Twitter-Client,代码行数:36,代码来源:twitter.go

示例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
}
开发者ID:tommed,项目名称:GoogleGo-Twitter-Client,代码行数:39,代码来源:twitter.go

示例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
}
开发者ID:COTOHA,项目名称:gorrdpd,代码行数:7,代码来源:logger.go

示例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)
		}
	}
}
开发者ID:COTOHA,项目名称:gorrdpd,代码行数:28,代码来源:udp_generator.go

示例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)
}
开发者ID:tommed,项目名称:GoogleGo-Twitter-Client,代码行数:8,代码来源:ui.go

示例12: Process

func (bot *Bot) Process(message *Message, out chan string) {
	switch message.Command {
	case "PING":
		message.Ping(out)
	default:
		log.Stdoutf("%#v", message)
	}
}
开发者ID:davecheney,项目名称:gobot,代码行数:8,代码来源:bot.go

示例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)
	}
}
开发者ID:iamnafets,项目名称:web.go,代码行数:9,代码来源:web.go

示例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)
	}
}
开发者ID:surapaneni,项目名称:web.go,代码行数:10,代码来源:web.go

示例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
}
开发者ID:bedwards,项目名称:goextdirect,代码行数:19,代码来源:example.go


注:本文中的log.Stdoutf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。