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


Golang Time.Seconds函数代码示例

本文整理汇总了Golang中Time.Seconds函数的典型用法代码示例。如果您正苦于以下问题:Golang Seconds函数的具体用法?Golang Seconds怎么用?Golang Seconds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Seconds函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: showHandler

func showHandler(backend appchilada.Backend) func(http.ResponseWriter, *http.Request) {
	getTemplate := getTemplateFunc("resources/show.html")
	return func(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		name := r.URL.Path[len("/show/"):]
		var start, end int64
		if startVal := r.Form.Get("start"); startVal != "" {
			start, _ = strconv.Atoi64(startVal)
		} else {
			// Default to last 24 hours
			start = time.Seconds() - 86400
		}
		if endVal := r.Form.Get("end"); endVal != "" {
			end, _ = strconv.Atoi64(endVal)
		} else {
			// Default to now
			end = time.Seconds()
		}
		results, err := backend.Read(name, appchilada.Interval{start, end})
		if err != nil {
			// TODO Output error in response
			log.Printf("Error getting results for %s: %v", name, err)
			return
		}
		if err := getTemplate().Execute(w, results); err != nil {
			log.Printf("Error executing template: %v", err)
		}
	}
}
开发者ID:hlubek,项目名称:appchilada,代码行数:29,代码来源:frontend.go

示例2: Create

func (self *TarwFS) Create(name string, flags, mode uint32) (file fuse.File, eno fuse.Status) {
	//log.Printf("Create:%s", name)
	self.lock.Lock()
	_, exists := self.isDir[name]
	if !exists {
		self.files[name] = &os.FileInfo{Mode: mode | syscall.S_IFREG}
		self.isDir[name] = false
		self.lock.Unlock()
		start := time.Seconds()
		file = newFile(func(r io.Reader, rlen int64) (err os.Error) {
			self.lock.Lock()
			err = self.w.WriteHeader(&tar.Header{
				Typeflag: tar.TypeReg,
				Name:     name,
				Mode:     int64(mode),
				Size:     rlen,
				Ctime:    start,
				Mtime:    time.Seconds(),
				Atime:    time.Seconds(),
			})
			if err == nil {
				_, err = io.Copyn(self.w, r, rlen)
			}
			self.lock.Unlock()
			return
		})
		eno = fuse.OK
	} else {
		self.lock.Unlock()
		eno = fuse.EINVAL
	}
	return
}
开发者ID:abneptis,项目名称:tarwfs,代码行数:33,代码来源:mounted.go

示例3: timer

func timer(sess string, killme chan bool) {
	limit := time.Seconds() + 5
	for {
		/*
		   _,test := killme;
		   if !test {
		       return;
		   }
		*/
		select {
		case <-killme:
			return
		default:
			if limit < time.Seconds() {
				_, test1 := sessions[sess]
				if test1 {
					sessions[sess] <- "timeout"
				}
				close(killme)
				return

			}
			time.Sleep(1000000000)

		}
	}
	return
}
开发者ID:stampzilla,项目名称:stampzilla,代码行数:28,代码来源:jonaz.go

示例4: timeoutCloser

// Close connections that have been idle for > p.timeout seconds.
func timeoutCloser(p *pool) {
	for p != nil && !p.closed {
		p.cond.L.Lock()
		now := time.Seconds()
		delay := 1e9 * p.timeout
		for p.conns.Len() > 0 {
			front := p.conns.Front()
			pc := front.Value.(poolConn)
			atime := pc.atime
			if (now - atime) > p.timeout {
				pc.Conn.Close()
				p.conns.Remove(front)
				p.n--
				p.log("idle connection closed")
			} else {
				// Wait until first connection would timeout if it isn't used.
				delay = 1e9 * (p.timeout - (now - atime) + 1)
				break
			}
		}
		// don't let the pool fall below the min
		for i := p.n; i < p.min; i++ {
			c, err := Connect(p.params, LogError)
			if err != nil {
				p.log("can't create connection")
			} else {
				p.conns.PushFront(poolConn{c, time.Seconds()})
				p.n++
			}
		}
		p.cond.L.Unlock()
		time.Sleep(delay)
	}
	p.log("timeoutCloser finished")
}
开发者ID:samuel,项目名称:go-pgsql,代码行数:36,代码来源:pool.go

示例5: convert

func (h OpenOrders) convert() (o xgen.OpenOrders) { // Convert campbx.OpenOrders to xgen.OpenOrders
	var err os.Error
	o.Sell = make(map[string]xgen.OpenOrder)
	o.Buy = make(map[string]xgen.OpenOrder)
	for _, order := range h.Buy {
		if order.Oid != "" {
			var t xgen.OpenOrder
			t.Date = time.Seconds() // Should use time.Parse to convert order.DateEntered to Unix time
			t.Price, err = strconv.Atof64(order.Price)
			check(err)
			t.Amount, err = strconv.Atof64(order.Quantity)
			check(err)
			o.Buy[order.Oid] = t
		}
	}
	for _, order := range h.Sell {
		if order.Oid != "" {
			var t xgen.OpenOrder
			t.Date = time.Seconds() // Should use time.Parse to convert order.DateEntered to Unix time
			t.Price, err = strconv.Atof64(order.Price)
			check(err)
			t.Amount, err = strconv.Atof64(order.Quantity)
			check(err)
			o.Sell[order.Oid] = t
		}
	}
	return
}
开发者ID:adrianuswarmenhoven,项目名称:ArBit,代码行数:28,代码来源:campbxapi.go

示例6: TestObjectId

func TestObjectId(t *testing.T) {
	t1 := time.Seconds()
	min := MinObjectIdForTime(t1)
	id := NewObjectId()
	max := MaxObjectIdForTime(time.Seconds())
	if id < min {
		t.Errorf("%q < %q", id, min)
	}
	if id > max {
		t.Errorf("%q > %q", id, max)
	}
	if min.CreationTime() != t1 {
		t.Errorf("min.CreationTime() = %d, want %d", min.CreationTime(), t1)
	}
	id2, err := NewObjectIdHex(id.String())
	if err != nil {
		t.Errorf("NewObjectIdString returned %q", err)
	}
	if id2 != id {
		t.Errorf("%q != %q", id2, id)
	}
	t2 := ObjectId("").CreationTime()
	if t2 != 0 {
		t.Error("creation time for invalid id = %d, want 0", t1)
	}
}
开发者ID:xuechengbao,项目名称:go-mongo,代码行数:26,代码来源:bson_test.go

示例7: init

func init() {
	start := time.Seconds()
	Publish("runtime", map[string]interface{}{
		"cgocalls":   Func(func() interface{} { return runtime.Cgocalls() }),
		"goroutines": Func(func() interface{} { return runtime.Goroutines() }),
		"version":    runtime.Version(),
		"memstats":   &runtime.MemStats,
	})
	Publish("uptimeSeconds", Func(func() interface{} { return time.Seconds() - start }))
	Publish("cmdline", &os.Args)
}
开发者ID:adamsxu,项目名称:twister,代码行数:11,代码来源:expvar.go

示例8: SetValue

// Set Value From HTMLForm Values
func (t *Tasks) SetValue(Id string, r *http.Request) os.Error {

	var err os.Error

	t.UserId = Id
	t.KeyID, err = strconv.Atoi64(r.FormValue(FORM_KEY))
	if err != nil {
		t.KeyID = 0
	}
	t.Status, err = strconv.Atoi(r.FormValue(FORM_STATUS))
	if err != nil {
		log.Println(err)
		return err
	}

	log.Println("Status")

	t.Context = html.EscapeString(r.FormValue(FORM_CONTEXT))
	t.IsUseLimit, err = strconv.Atob(r.FormValue(FORM_LIMIT))
	if err != nil {
		log.Println(err)
		return err
	}

	log.Println("IsUseLimit")

	t.IsComplete = (t.Status == 2)
	t.IsCanceld = (t.Status == 9)

	log.Println("Set Bool Value")

	if t.IsUseLimit {

		log.Println(r.FormValue(FORM_DATE))
		log.Println(time.RFC3339)
		var limit *time.Time
		limit, err = time.Parse("2006-01-02 15:04:05", r.FormValue(FORM_DATE))
		if err == nil {
			t.PlanDate = datastore.SecondsToTime(limit.Seconds())
		} else {
			log.Println(err)
			return err
		}
	}

	log.Println("PostDate")
	t.PostDate = datastore.SecondsToTime(time.Seconds())
	if t.IsComplete {
		t.CompleteDate = datastore.SecondsToTime(time.Seconds())
	}

	return nil

}
开发者ID:dotroidxx,项目名称:d3tasks,代码行数:55,代码来源:models.go

示例9: WaitOnline

func WaitOnline(id, maxWait int) os.Error {
	start := time.Seconds()
	for tc.nodes[id].Cluster.MyNode.Status != cluster.Status_Online {
		if time.Seconds()-start > int64(maxWait) {
			return os.NewError("Maximum wait time exceed")
		}

		time.Sleep(1000000) // 1 ms
	}

	return nil
}
开发者ID:appaquet,项目名称:gostore,代码行数:12,代码来源:cluster_test.go

示例10: newPing

//
// Receive and process a new ping
//
// PING node nodeid nodetype hash
// PING 192.168.1.5 1 slave cf81a8580f8296424ee7589c3aca3b83981af958
//
func (myDHTServer *DHTServerStruct) newPing(con *net.TCPConn, s string, chall string) {

	fields := strings.Split(s, " ", 0)

	if len(fields) != 5 {
		// Not enough fields just exit
		myDHTServer.logger.Logf(LMED, "Received ping with insufficient params")
		return
	}

	// Authenticate
	sharesp := fields[4]
	shap := SHA1String(fmt.Sprintf("%s%s", chall, G_clusterKey))
	shastr := fmt.Sprintf("%x", shap)
	if shastr != sharesp {
		myDHTServer.logger.Logf(LMIN, "Failed PING: %s %s", fields[1], fields[2])
		return
	}

	if compareConWithIPString(con, fields[1]) == false {
		myDHTServer.logger.Logf(LMIN, "Bad PING, RemoteAddr and IP parameter different: %s %s", con.RemoteAddr().String(), fields[1])
		return
	}

	// Does this IP address or node already exist?
	G_nodesLock.Lock()
	for c := range G_nodes.Iter() {
		if (c.(*nodesInClusterStruct).ip == fields[1]) && (c.(*nodesInClusterStruct).nodeid == fields[2]) {
			// Already exits, great
			// Update time stamp
			c.(*nodesInClusterStruct).lastPing = time.Seconds()
			G_nodesLock.Unlock() // listCluster uses G_nodesLock
			myDHTServer.listCluster(con)
			return
		}
	}

	// Need to check for IP in list with different nodeid and vice versa
	// TDB

	n := new(nodesInClusterStruct)
	n.ip = fields[1]
	n.nodeid = fields[2]
	n.nodetype = fields[3]
	n.lastPing = time.Seconds()
	G_nodes.PushBack(n)
	G_nodesLock.Unlock()

	myDHTServer.logger.Logf(LMED, "New %s node joins cluster %s %s", fields[3], fields[1], fields[2])
	myDHTServer.listCluster(con)
}
开发者ID:GoogleSourceExpoted,项目名称:goesmtp,代码行数:57,代码来源:DHTServer.go

示例11: sieves

// The prime sieve: Daisy-chain filter processes together.
func sieves(w http.ResponseWriter, r *http.Request) {
	start := time.Seconds()
	fmt.Fprintf(w, "the first %v prime numbers are:<br />", NUM_PRIMES)
	ch := make(chan int)              // Create a new channel.
	go generate(ch)                   // Start generate() as a goroutine.
	for i := 0; i < NUM_PRIMES; i++ { // Print the first hundred primes.
		prime := <-ch
		fmt.Fprintf(w, "%v<br />", prime)
		ch1 := make(chan int)
		go filter(ch, ch1, prime)
		ch = ch1
	}
	end := time.Seconds()
	fmt.Fprintf(w, "<br /><br />the computation took %v seconds", end-start)
}
开发者ID:nlake44,项目名称:sample-apps,代码行数:16,代码来源:sieves.go

示例12: register

func register(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	g := Member{
		Usern:    r.FormValue("usern"),
		Name:     r.FormValue("name"),
		Passwd:   r.FormValue("passwd"),
		Repasswd: r.FormValue("repasswd"),
		Phone:    r.FormValue("phone"),
		Email:    r.FormValue("email"),
		Study:    r.FormValue("study"),
		Address:  r.FormValue("address"),
		Date:     datastore.SecondsToTime(time.Seconds()),
	}

	if g.Passwd == g.Repasswd && g.Usern != "" && g.Name != "" && g.Phone != "" && g.Email != "" {
		_, err := datastore.Put(c, datastore.NewIncompleteKey("Member"), &g)

		if err != nil {
			http.Error(w, err.String(), http.StatusInternalServerError)
			return
		}

	} else {
		http.Redirect(w, r, "/signin", http.StatusFound)
	}
	http.Redirect(w, r, "/view", http.StatusFound)
}
开发者ID:OOgosite,项目名称:Online-ticket-reservation-system,代码行数:27,代码来源:signin.go

示例13: timeoutCloser

// Close connections that have been idle for > p.timeout seconds.
func timeoutCloser(p *pool) {
	for p != nil && !p.closed {
		p.cond.L.Lock()
		now := time.Seconds()
		delay := 1e9 * p.timeout
		for p.conns.Len() > 0 {
			front := p.conns.Front()
			pc := front.Value.(poolConn)
			atime := pc.atime
			if (now - atime) > p.timeout {
				pc.Conn.Close()
				p.conns.Remove(front)
				p.n--
				p.log("idle connection closed")
			} else {
				// Wait until first connection would timeout if it isn't used.
				delay = 1e9 * (p.timeout - (now - atime) + 1)
				break
			}
		}
		p.cond.L.Unlock()
		time.Sleep(delay)
	}
	p.log("timeoutCloser finished")
}
开发者ID:andradeandrey,项目名称:pgsql.go,代码行数:26,代码来源:pool.go

示例14: beginWatch

func beginWatch() {
	//fmt.Println("Begin watching...")
	if total > 0.5 || start == 0 {
		fmt.Println("Begin watching...")
		start = time.Seconds()
	}
}
开发者ID:Digaku,项目名称:ndayak,代码行数:7,代码来源:stats.go

示例15: GetSecureCookie

func (ctx *Context) GetSecureCookie(name string) (string, bool) {
	for _, cookie := range ctx.Request.Cookie {
		if cookie.Name != name {
			continue
		}

		parts := strings.SplitN(cookie.Value, "|", 3)

		val := parts[0]
		timestamp := parts[1]
		sig := parts[2]

		if getCookieSig(ctx.Server.Config.CookieSecret, []byte(val), timestamp) != sig {
			return "", false
		}

		ts, _ := strconv.Atoi64(timestamp)

		if time.Seconds()-31*86400 > ts {
			return "", false
		}

		buf := bytes.NewBufferString(val)
		encoder := base64.NewDecoder(base64.StdEncoding, buf)

		res, _ := ioutil.ReadAll(encoder)
		return string(res), true
	}
	return "", false
}
开发者ID:AndrewScott,项目名称:web.go,代码行数:30,代码来源:web.go


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