當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Stdout函數代碼示例

本文整理匯總了Golang中log.Stdout函數的典型用法代碼示例。如果您正苦於以下問題:Golang Stdout函數的具體用法?Golang Stdout怎麽用?Golang Stdout使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Stdout函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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!")
}
開發者ID:r0m1bl,項目名稱:Go-Redis,代碼行數:57,代碼來源:connection.go

示例2: ParseUser

// Use regexp's to parse userstrings
func ParseUser(s string) (u *IRCUser) {
	u = new(IRCUser)
	log.Stdout("Got User", s)
	a := userExp.MatchStrings(s)
	log.Stdout("Parsed", len(a))
	if len(a) > 0 { // Got a nick
		u.Nick = a[1]
		u.User = a[2]
	}
	return u
}
開發者ID:machinaut,項目名稱:go-play,代碼行數:12,代碼來源:irc2.go

示例3: 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

示例4: 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

示例5: 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

示例6: main

func main() {
	addr, err := net.ResolveTCPAddr("127.0.0.1:4009")
	if err != nil {
		log.Exit("error:", err)
	}
	listener, err := net.ListenTCP("tcp", addr)
	if err != nil {
		log.Exit("error", err)
	}

	//1 channel for incoming connections, another for client communication
	connections := make(chan *net.TCPConn)
	clients := make(chan TClient)
	cMap := make(map[string]*net.TCPConn)
	fMap := make(map[string]string)

	go ListenConnections(listener, connections, clients)
	log.Stdout("Waiting for connections\n")
	for {
		select {
		case conn := <-connections:
			cMap[conn.RemoteAddr().String()] = conn
		case client := <-clients:
			if regexp.MustCompile("^have ").MatchString(client.msg) {
				fMap[string(client.msg[5:len(client.msg)])] = client.local
			}
			if regexp.MustCompile("^list").MatchString(client.msg) {
				for key, value := range fMap {
					cMap[client.forserver].Write(strings.Bytes(key + "->" + value))
				}
				cMap[client.forserver].Write(strings.Bytes("\n"))
			}
		}
	}
}
開發者ID:WalterShe,項目名稱:gop2p,代碼行數:35,代碼來源:server.go

示例7: Close

// closes the connHdl's net.Conn connection.
// Is public so that connHdl struct can be used as SyncConnection (TODO: review that.)
//
func (hdl connHdl) Close() os.Error {
	err := hdl.conn.Close()
	if debug() {
		log.Stdout("[Go-Redis] Closed connection: ", hdl)
	}
	return err
}
開發者ID:r0m1bl,項目名稱:Go-Redis,代碼行數:10,代碼來源:connection.go

示例8: ProcessConn

func ProcessConn(conn *net.TCPConn, client chan TClient) {
	log.Stdout("connected\n")

	//get client's ip and port
	conn.Write(strings.Bytes("hi"))
	go myReader(conn, client)
}
開發者ID:WalterShe,項目名稱:gop2p,代碼行數:7,代碼來源:server.go

示例9: main

func main() {
	var response *http.Response
	var err error

	api := notifo.New("gotest", "a25c4f206494150bddf2e716705c8bedcad0cb16")
	//api.SetEndpoint("http://localhost:8000/v1/");

	if response, err = api.SubscribeUser("devcamcar"); err != nil {
		log.Stderr("ERROR")
		log.Stderr(err)
	} else {
		dump, _ := httputil.DumpResponse(response, true)
		log.Stdout(response.StatusCode)
		log.Stdout(string(dump))
	}
}
開發者ID:dustin,項目名稱:notifo.go,代碼行數:16,代碼來源:notifo_tests.go

示例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
}
開發者ID:andradeandrey,項目名稱:gomemcached,代碼行數:30,代碼來源:mc_conn_handler.go

示例11: main

func main() {
	// option setup
	opts.Description = "lightweight http blog server"
	// parse and handle options
	opts.Parse()

	confFile = path.Join(*blogroot, "config")
	templateDir = path.Join(*blogroot, "templates")
	postDir = path.Join(*blogroot, "posts")
	pageDir = path.Join(*blogroot, "pages")
	dataDir = path.Join(*blogroot, "data")

	config.ReadConfig(confFile)
	input.ReadTemplates(templateDir)
	input.ReadPosts(postDir)
	input.ReadPages(pageDir)
	input.ReadData(dataDir)
	makeTags()
	makeCategories()
	compile.CompileAll()
	serve.StartServers()
	log.Stdout("Server started in ",
		(time.Nanoseconds()-startTime)/1000,
		" microseconds")
	serve.Serve(*port)
}
開發者ID:bytbox,項目名稱:obsidian,代碼行數:26,代碼來源:main.go

示例12: newConnHdl

// Creates and opens a new connection to server per ConnectionSpec.
// The new connection is wrapped by a new connHdl with its bufio.Reader
// delegating to the net.Conn's reader.
//
func newConnHdl(spec *ConnectionSpec) (hdl *connHdl, err Error) {
	here := "newConnHdl"

	if hdl = new(connHdl); hdl == nil {
		return nil, NewError(SYSTEM_ERR, fmt.Sprintf("%s(): failed to allocate connHdl", here))
	}
	addr := fmt.Sprintf("%s:%d", spec.host, spec.port)
	raddr, e := net.ResolveTCPAddr(addr)
	if e != nil {
		msg := fmt.Sprintf("%s(): failed to resolve remote address %s", here, addr)
		return nil, NewErrorWithCause(SYSTEM_ERR, msg, e)
	}
	conn, e := net.DialTCP(TCP, nil, raddr)
	switch {
	case e != nil:
		err = NewErrorWithCause(SYSTEM_ERR, fmt.Sprintf("%s(): could not open connection", here), e)
	case conn == nil:
		err = NewError(SYSTEM_ERR, fmt.Sprintf("%s(): net.Dial returned nil, nil (?)", here))
	default:
		configureConn(conn, spec)
		hdl.spec = spec
		hdl.conn = conn
		bufsize := 4096
		hdl.reader, e = bufio.NewReaderSize(conn, bufsize)
		if e != nil {
			msg := fmt.Sprintf("%s(): bufio.NewReaderSize (%d) error", here, bufsize)
			err = NewErrorWithCause(SYSTEM_ERR, msg, e)
		} else {
			if err = hdl.onConnect(); err == nil && debug() {
				log.Stdout("[Go-Redis] Opened SynchConnection connection to ", addr)
			}
		}
	}
	return hdl, err
}
開發者ID:r0m1bl,項目名稱:Go-Redis,代碼行數:39,代碼來源:connection.go

示例13: VisitFile

func (v pageVisitor) VisitFile(path string, f *os.FileInfo) {
	// get a clean path
	relPath := strings.Replace(path, v.root, "", 1)
	log.Stdout("  Reading page ", relPath)
	// read in the posts
	Pages[relPath] = ReadPage(readFile(path), relPath)
}
開發者ID:bytbox,項目名稱:obsidian,代碼行數:7,代碼來源:input.go

示例14:

// Creates and opens a new connection to server per ConnectionSpec.
// The new connection is wrapped by a new connHdl with its bufio.Reader
// delegating to the net.Conn's reader. 
//
func newConnHdl (spec *ConnectionSpec) (hdl *connHdl, err os.Error) {
	here := "newConnHdl";

	if hdl = new(connHdl); hdl == nil { 
		return nil, withNewError (fmt.Sprintf("%s(): failed to allocate connHdl", here));
	}
	addr := fmt.Sprintf("%s:%d", spec.host, spec.port); 
	raddr, e:= net.ResolveTCPAddr(addr); 
	if e != nil {
		return nil, withNewError (fmt.Sprintf("%s(): failed to resolve remote address %s", here, addr));
	}	
	conn, e:= net.DialTCP(TCP, nil, raddr);
	switch {
		case e != nil:
			err = withOsError (fmt.Sprintf("%s(): could not open connection", here), e);
		case conn == nil:
			err = withNewError (fmt.Sprintf("%s(): net.Dial returned nil, nil (?)", here));
		default:
			configureConn(conn, spec);
			hdl.spec = spec;
			hdl.conn = conn;
			bufsize := 4096;
			hdl.reader, e = bufio.NewReaderSize(conn, bufsize);
			if e != nil {
				err = withNewError (fmt.Sprintf("%s(): bufio.NewReaderSize (%d) error", here, bufsize));
			}
			else {
				if debug() {log.Stdout("[Go-Redis] Opened SynchConnection connection to ", addr);}
			}
	}
	return hdl, err;
}
開發者ID:evangineer,項目名稱:Go-Redis,代碼行數:36,代碼來源:connection.go

示例15: 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


注:本文中的log.Stdout函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。