當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。