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


Golang Time.SecondsToUTC函数代码示例

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


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

示例1: SetHeaders

func (this *ServiceContext) SetHeaders(code, timeout int, ctype string, modified int64) {
	t := time.UTC()
	t = time.SecondsToUTC(t.Seconds() + int64(timeout))
	ts := t.Format(time.RFC1123)

	this.Conn.SetHeader("Cache-Control", fmt.Sprintf("max-age=%d; must-revalidate", timeout))
	this.Conn.SetHeader("Expires", fmt.Sprintf("%s GMT", ts[0:len(ts)-4]))

	if modified > 0 {
		t = time.SecondsToUTC(modified)
	} else {
		t = time.UTC()
	}

	ts = t.Format(time.RFC1123)

	this.Conn.SetHeader("Last-Modified", fmt.Sprintf("%s GMT", ts[0:len(ts)-4]))
	this.Conn.SetHeader("Content-Type", ctype)
	this.Conn.SetHeader("Server", context.Config().ServerName)

	if this.Compressed {
		this.Conn.SetHeader("Content-Encoding", "gzip")
	}

	this.Conn.WriteHeader(code)
}
开发者ID:welterde,项目名称:mudkip,代码行数:26,代码来源:servicecontext.go

示例2: String

func (self *Generation) String() string {
	r := fmt.Sprintf("Generation [%s-%s]", time.SecondsToUTC(self.startEpoch), time.SecondsToUTC(self.startEpoch+GenerationSize))
	for key, _ := range self.inhabitants {
		r += fmt.Sprintf("\n %s", key)
	}
	return r
}
开发者ID:rodolf0,项目名称:gocached,代码行数:7,代码来源:generationalstorage.go

示例3: TestCRLCreation

func TestCRLCreation(t *testing.T) {
	block, _ := pem.Decode([]byte(pemPrivateKey))
	priv, _ := ParsePKCS1PrivateKey(block.Bytes)
	block, _ = pem.Decode([]byte(pemCertificate))
	cert, _ := ParseCertificate(block.Bytes)

	now := time.SecondsToUTC(1000)
	expiry := time.SecondsToUTC(10000)

	revokedCerts := []pkix.RevokedCertificate{
		{
			SerialNumber:   big.NewInt(1),
			RevocationTime: now,
		},
		{
			SerialNumber:   big.NewInt(42),
			RevocationTime: now,
		},
	}

	crlBytes, err := cert.CreateCRL(rand.Reader, priv, revokedCerts, now, expiry)
	if err != nil {
		t.Errorf("error creating CRL: %s", err)
	}

	_, err = ParseDERCRL(crlBytes)
	if err != nil {
		t.Errorf("error reparsing CRL: %s", err)
	}
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:30,代码来源:x509_test.go

示例4: TestCreateSelfSignedCertificate

func TestCreateSelfSignedCertificate(t *testing.T) {
	random := rand.Reader

	block, _ := pem.Decode([]byte(pemPrivateKey))
	priv, err := ParsePKCS1PrivateKey(block.Bytes)
	if err != nil {
		t.Errorf("Failed to parse private key: %s", err)
		return
	}

	template := Certificate{
		SerialNumber: []byte{1},
		Subject: Name{
			CommonName:   "test.example.com",
			Organization: []string{"Acme Co"},
		},
		NotBefore: time.SecondsToUTC(1000),
		NotAfter:  time.SecondsToUTC(100000),

		SubjectKeyId: []byte{1, 2, 3, 4},
		KeyUsage:     KeyUsageCertSign,

		BasicConstraintsValid: true,
		IsCA:     true,
		DNSNames: []string{"test.example.com"},

		PolicyIdentifiers:   []asn1.ObjectIdentifier{[]int{1, 2, 3}},
		PermittedDNSDomains: []string{".example.com", "example.com"},
	}

	derBytes, err := CreateCertificate(random, &template, &template, &priv.PublicKey, priv)
	if err != nil {
		t.Errorf("Failed to create certificate: %s", err)
		return
	}

	cert, err := ParseCertificate(derBytes)
	if err != nil {
		t.Errorf("Failed to parse certificate: %s", err)
		return
	}

	if len(cert.PolicyIdentifiers) != 1 || !cert.PolicyIdentifiers[0].Equal(template.PolicyIdentifiers[0]) {
		t.Errorf("Failed to parse policy identifiers: got:%#v want:%#v", cert.PolicyIdentifiers, template.PolicyIdentifiers)
	}

	if len(cert.PermittedDNSDomains) != 2 || cert.PermittedDNSDomains[0] != ".example.com" || cert.PermittedDNSDomains[1] != "example.com" {
		t.Errorf("Failed to parse name constraints: %#v", cert.PermittedDNSDomains)
	}

	err = cert.CheckSignatureFrom(cert)
	if err != nil {
		t.Errorf("Signature verification failed: %s", err)
		return
	}
}
开发者ID:go-nosql,项目名称:golang,代码行数:56,代码来源:x509_test.go

示例5: SetCookie

func (ctx Context) SetCookie(key string, val string, exp int64) {
	var utc *time.Time
	if exp == 0 {
		utc = time.SecondsToUTC(2147483647) // year 2038
	} else {
		utc = time.SecondsToUTC(time.UTC().Seconds() + exp)
	}
	cookie := fmt.Sprintf("%s=%s; expires=%s", key, val, webTime(utc))
	ctx.SetHeader("Set-Cookie", cookie)
}
开发者ID:pimienta,项目名称:appgo,代码行数:10,代码来源:app.go

示例6: main

func main() {
	flag.Parse()

	urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0)
	if err != nil {
		log.Exitf("failed to open /dev/urandom: %s", err)
		return
	}

	priv, err := rsa.GenerateKey(urandom, 1024)
	if err != nil {
		log.Exitf("failed to generate private key: %s", err)
		return
	}

	now := time.Seconds()

	template := x509.Certificate{
		SerialNumber: []byte{0},
		Subject: x509.Name{
			CommonName:   *hostName,
			Organization: "Acme Co",
		},
		NotBefore: time.SecondsToUTC(now - 300),
		NotAfter:  time.SecondsToUTC(now + 60*60*24*365), // valid for 1 year.

		SubjectKeyId: []byte{1, 2, 3, 4},
		KeyUsage:     x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
	}

	derBytes, err := x509.CreateCertificate(urandom, &template, &template, &priv.PublicKey, priv)
	if err != nil {
		log.Exitf("Failed to create certificate: %s", err)
		return
	}

	certOut, err := os.Open("cert.pem", os.O_WRONLY|os.O_CREAT, 0644)
	if err != nil {
		log.Exitf("failed to open cert.pem for writing: %s", err)
		return
	}
	pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
	certOut.Close()
	log.Print("written cert.pem\n")

	keyOut, err := os.Open("key.pem", os.O_WRONLY|os.O_CREAT, 0600)
	if err != nil {
		log.Print("failed to open key.pem for writing:", err)
		return
	}
	pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
	keyOut.Close()
	log.Print("written key.pem\n")
}
开发者ID:GNA-SERVICES-INC,项目名称:MoNGate,代码行数:54,代码来源:generate_cert.go

示例7: SetCookie

//Sets a cookie -- duration is the amount of time in seconds. 0 = forever
func (ctx *Context) SetCookie(name string, value string, age int64) {
	var utctime *time.Time
	if age == 0 {
		// 2^31 - 1 seconds (roughly 2038)
		utctime = time.SecondsToUTC(2147483647)
	} else {
		utctime = time.SecondsToUTC(time.UTC().Seconds() + age)
	}
	cookie := fmt.Sprintf("%s=%s; expires=%s", name, value, webTime(utctime))
	ctx.SetHeader("Set-Cookie", cookie, false)
}
开发者ID:AndrewScott,项目名称:web.go,代码行数:12,代码来源:web.go

示例8: LastModified

func (p *viewAccountContext) LastModified() *time.Time {
	var lastModified *time.Time
	if p.user != nil && p.user.ModifiedAt != 0 {
		lastModified = time.SecondsToUTC(p.user.ModifiedAt)
	} else if p.consumer != nil && p.consumer.ModifiedAt != 0 {
		lastModified = time.SecondsToUTC(p.consumer.ModifiedAt)
	} else if p.externalUser != nil && p.externalUser.ModifiedAt != 0 {
		lastModified = time.SecondsToUTC(p.externalUser.ModifiedAt)
	}
	return lastModified
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:11,代码来源:view.go

示例9: main

func main() {
	flag.Parse()
	timestamp := time.Seconds()

	if len(*hostname) == 0 {
		ErrorF("Error: Missing -hostname parameter.\n")
	}

	fmt.Printf(">>> Generating Private Key: %s\n", *hostname+".key.pem")
	private_key, error := rsa.GenerateKey(rand.Reader, *bits)

	if error != nil {
		ErrorF("Error: Unable to generate private key: %s\n", error)
	}

	private_key_file, error := os.OpenFile(*hostname+".key.pem", os.O_WRONLY|os.O_CREATE, 0600)

	if error != nil {
		ErrorF("Error: Unable to open %s for writing: %s\n", *hostname+".key.pem", error)
	}

	defer private_key_file.Close()

	pem.Encode(private_key_file, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(private_key)})

	template := x509.Certificate{
		SerialNumber: []byte{0},
		Subject: x509.Name{
			CommonName:   *hostname,
			Organization: []string{*organization},
		},
		NotBefore:    time.SecondsToUTC(timestamp),
		NotAfter:     time.SecondsToUTC(365*24*60*60 + timestamp),
		SubjectKeyId: []byte{1, 3, 3, 7},
		KeyUsage:     x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
	}

	fmt.Printf(">>> Generating Certificate: %s\n", *hostname+".pem")
	certificate, error := x509.CreateCertificate(rand.Reader, &template, &template, &private_key.PublicKey, private_key)

	if error != nil {
		ErrorF("Error: Unable to generate certificate: %s\n", error)
	}

	certificate_file, error := os.OpenFile(*hostname+".pem", os.O_WRONLY|os.O_CREATE, 0644)

	if error != nil {
		ErrorF("Error: Unable to open %s for writing: %s\n", *hostname+".pem", error)
	}

	defer certificate_file.Close()

	pem.Encode(certificate_file, &pem.Block{Type: "CERTIFICATE", Bytes: certificate})
}
开发者ID:ahf,项目名称:ircd-novo,代码行数:54,代码来源:novo-genssl.go

示例10: parseActDetail

///func parseActDetail(c appengine.Context, r *io.ReadCloser, res *ActDetail) (*ActDetail, os.Error) {
func parseActDetail(c appengine.Context, res *ActDetail) (*ActDetail, os.Error) {
	tmp := strings.NewReader(sampleActHtml)
	r := &tmp
	n, err := html.Parse(*r)
	if err != nil {
		c.Errorf("%s", err.String())
		return nil, err
	}

	nc := NewCursor(n)
	nc = nc.FindById("body1")
	nc.Prune()

	curr := nc.FindText("Activity Type:").Parent().NextSibling().Node.Child[0]
	res.Type = curr.Data

	curr = nc.FindText("Name:").Parent().NextSibling().Node.Child[0]
	res.Name = curr.Data

	curr = nc.FindText("Description:").Parent().NextSibling().Node.Child[0]
	res.Desc = curr.Data

	curr = nc.FindText("Location:").Parent().NextSibling().Node.Child[0]
	res.Location = curr.Data

	curr = nc.FindText("Start Date and Time:").Parent().NextSibling().Node.Child[0]
	res.Start, err = time.Parse("02 Jan 2006\u00a015:04", curr.Data)
	res.Start = time.SecondsToUTC(res.Start.Seconds())
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("Finish Date and Time:").Parent().NextSibling().Node.Child[0]
	res.End, err = time.Parse("02 Jan 2006\u00a015:04", curr.Data)
	res.End = time.SecondsToUTC(res.End.Seconds())
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("No of Cadets:").Parent().NextSibling().Node.Child[0]
	res.NCadets, err = strconv.Atoi(curr.Data)
	if err != nil {
		return nil, err
	}

	curr = nc.FindText("No of Staff:").Parent().NextSibling().Node.Child[0]
	res.NStaff, err = strconv.Atoi(curr.Data)
	if err != nil {
		return nil, err
	}

	return res, nil
}
开发者ID:qtse,项目名称:go_fetch,代码行数:54,代码来源:fetch.go

示例11: SetCookie

//Sets a cookie -- duration is the amount of time in seconds.
// 0 = forever, persistent
// <0 = omit expires attribute, i.e. expire at end of browser session
func (ctx *Context) SetCookie(name string, value string, age int64) {
	cookie := fmt.Sprintf("%s=%s", name, value)
	if age == 0 {
		// 2^31 - 1 seconds (roughly 2038)
		utctime := time.SecondsToUTC(2147483647)
		cookie += fmt.Sprintf("; expires=%s", webTime(utctime))
	} else if age > 0 {
		utctime := time.SecondsToUTC(time.UTC().Seconds() + age)
		cookie += fmt.Sprintf("; expires=%s", webTime(utctime))
	}
	cookie += fmt.Sprintf("; path=/")
	ctx.SetHeader("Set-Cookie", cookie, false)
}
开发者ID:axel-b,项目名称:web.go,代码行数:16,代码来源:web.go

示例12: OutputTo

func (p *HtmlDirectoryListing) OutputTo(req Request, cxt Context, writer io.Writer, resp ResponseWriter) {
	result := new(htmlDirectoryEntryResult)
	result.Path = p.urlPath
	result.Tail = path.Base(p.urlPath)
	var err os.Error
	defer func() {
		if p.file != nil {
			p.file.Close()
			p.file = nil
		}
	}()
	if p.file == nil {
		p.file, err = os.Open(p.fullPath)
		if err != nil {
			result.Message = err.String()
			result.Result = make([]htmlDirectoryEntry, 0)
			HTML_DIRECTORY_LISTING_ERROR_TEMPLATE.Execute(writer, result)
			return
		}
	}
	fileInfos, err := p.file.Readdir(-1)
	if err != nil {
		result.Message = err.String()
		result.Result = make([]htmlDirectoryEntry, 0)
		HTML_DIRECTORY_LISTING_ERROR_TEMPLATE.Execute(writer, result)
		return
	}
	entries := make([]htmlDirectoryEntry, len(fileInfos))
	for i, fileInfo := range fileInfos {
		entries[i].Filename = fileInfo.Name
		entries[i].Path = path.Join(p.urlPath, fileInfo.Name)
		entries[i].Size = fileInfo.Size
		entries[i].IsDirectory = fileInfo.IsDirectory()
		if fileInfo.IsDirectory() {
			entries[i].IsDirectory = true
			entries[i].Size = 0
		} else {
			entries[i].IsDirectory = false
			entries[i].Size = fileInfo.Size
		}
		entries[i].LastModified = time.SecondsToUTC(int64(fileInfo.Mtime_ns / 1e9)).Format(time.ANSIC)
	}
	dirInfo, _ := p.file.Stat()
	if dirInfo != nil {
		result.LastModified = time.SecondsToUTC(int64(dirInfo.Mtime_ns / 1e9)).Format(time.ANSIC)
	}
	result.Status = "success"
	result.Message = ""
	result.Result = entries
	HTML_DIRECTORY_LISTING_SUCCESS_TEMPLATE.Execute(writer, result)
}
开发者ID:pombredanne,项目名称:webmachine.go,代码行数:51,代码来源:directorylisting.go

示例13: postHandler

func postHandler(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	if cv := req.FormValue("cookie"); cv != "" {
		trace("postHandler recieved param cookie %s.", cv)
		cp := strings.SplitN(cv, "=", 2)
		if cp[1] != "-DELETE-" {
			exp := time.SecondsToUTC(time.UTC().Seconds() + 7*24*3600).Format(http.TimeFormat) // Now + 7 days
			w.Header().Set("Set-Cookie", fmt.Sprintf("%s=%s; Path=/de/index; expires=%s; Domain=my.domain.org; Secure;", cp[0], cp[1], exp))
		} else {
			trace("post-handler: Deleting cookie %s\n", cp[0])
			w.Header().Set("Set-Cookie", fmt.Sprintf("%s=%s; Path=/de/index; MaxAge=-1; Domain=my.domain.org; Secure;", cp[0], "X"))
		}
	}
	t := req.FormValue("q")
	if req.Method != "POST" {
		fmt.Printf("====== called /post with GET! ======\n")
	}

	_, header, err := req.FormFile("datei")
	if err == nil {
		info("Recieved datei: %s. %v", header.Filename, header.Filename == "file äöü 1.txt")
	}

	if t != "" {
		// w.Header().Set("Location", "http://localhost:54123/"+t)
		// w.Header().Set("Location", "localhost:54123/"+t)
		w.Header().Set("Location", "/"+t)
		w.WriteHeader(302)
	} else {
		text := req.FormValue("text")
		w.WriteHeader(200)
		body := "<html><body><h1>Post Page</h1><p>t = " + html.EscapeString(text) + "</p></body></html>"
		w.Write([]byte(body))
	}
}
开发者ID:vdobler,项目名称:webtest,代码行数:35,代码来源:suite_test.go

示例14: googleDateTimeStringToDsocial

func googleDateTimeStringToDsocial(s string) (d *DateTime) {
	if len(s) == 10 {
		// YYYY-MM-DD
		d = new(DateTime)
		year, _ := strconv.Atoi(s[0:4])
		month, _ := strconv.Atoi(s[5:7])
		day, _ := strconv.Atoi(s[8:10])
		d.Year = int16(year)
		d.Month = int8(month)
		d.Day = int8(day)
	} else if len(s) == 7 {
		t, err := time.Parse("--01-02", s)
		if err == nil && t != nil {
			d = new(DateTime)
			d.Month = int8(t.Month)
			d.Day = int8(t.Day)
		}
	} else if len(s) == 25 {
		// YYYY-MM-DDTHH:MM:SS-05:00
		t, err := time.Parse("2006-01-02T15:04:05-07:00", s)
		if err == nil && t != nil {
			t2 := time.SecondsToUTC(t.Seconds())
			d = new(DateTime)
			d.Year = int16(t2.Year)
			d.Month = int8(t2.Month)
			d.Day = int8(t2.Day)
			d.Hour = int8(t2.Hour)
			d.Minute = int8(t2.Minute)
			d.Second = int8(t2.Second)
		}
	}
	return
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:33,代码来源:convert_google.go

示例15: serveRecentPermanodes

func (sh *Handler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Request) {
	ret := jsonMap()
	defer httputil.ReturnJson(rw, ret)

	ch := make(chan *Result)
	errch := make(chan os.Error)
	go func() {
		errch <- sh.index.GetRecentPermanodes(ch, []*blobref.BlobRef{sh.owner}, 50)
	}()

	dr := sh.NewDescribeRequest()

	recent := jsonMapList()
	for res := range ch {
		dr.Describe(res.BlobRef, 2)
		jm := jsonMap()
		jm["blobref"] = res.BlobRef.String()
		jm["owner"] = res.Signer.String()
		t := time.SecondsToUTC(res.LastModTime)
		jm["modtime"] = t.Format(time.RFC3339)
		recent = append(recent, jm)
	}

	err := <-errch
	if err != nil {
		// TODO: return error status code
		ret["error"] = err.String()
		return
	}

	ret["recent"] = recent
	dr.PopulateJSON(ret)
}
开发者ID:ipeet,项目名称:camlistore,代码行数:33,代码来源:handler.go


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