本文整理匯總了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!")
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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"))
}
}
}
}
示例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
}
示例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)
}
示例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))
}
}
示例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() {
// 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)
}
示例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
}
示例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)
}
示例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;
}
示例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)
}
}
}