本文整理汇总了Golang中strconv.Atoi64函数的典型用法代码示例。如果您正苦于以下问题:Golang Atoi64函数的具体用法?Golang Atoi64怎么用?Golang Atoi64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Atoi64函数的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)
}
}
}
示例2: tfquery
func tfquery(req *http.Request) {
query := strings.Split(req.URL.RawQuery, "&", 0)
//fmt.Printf("path : %v\n", path)
//fmt.Printf("query: %v\n", query)
for i := 0; i < len(query); i++ {
nv := strings.Split(query[i], "=", 2)
if len(nv) == 2 {
switch nv[0] {
case "b":
begindate = nv[1]
case "e":
enddate = nv[1]
case "t":
title, _ = http.URLUnescape(nv[1])
case "c":
tcount, _ = strconv.Atoi(nv[1])
case "l":
lineheight, _ = strconv.Atoi64(nv[1])
case "p":
picwidth, _ = strconv.Atoi64(nv[1])
case "s":
spacing, _ = strconv.Atoi(nv[1])
case "m":
markerwidth, _ = strconv.Atoi64(nv[1])
}
}
//fmt.Printf("nv: %v\n", nv)
//showparams("Using ")
}
}
示例3: checkJoinByteRanges
func checkJoinByteRanges(t *testing.T, inputRangesStr string, expectedRangeStr string) {
inputRanges := make([]ByteRange, 0, 10)
appendRange := func(offset int64, length int64) {
inputRanges = inputRanges[0 : len(inputRanges)+1]
inputRanges[len(inputRanges)-1] = ByteRange{offset, length}
}
for _, rangeStr := range strings.Split(inputRangesStr, ",", -1) {
//print("Got \"", rangeStr, "\" from input \"", inputRangesStr, "\"\n")
if len(rangeStr) == 0 {
// Uh, this is stupid.
continue
}
parts := strings.Split(rangeStr, ":", 2)
offset, _ := strconv.Atoi64(parts[0])
length, _ := strconv.Atoi64(parts[1])
appendRange(offset, length)
}
actualRange := joinByteRanges(inputRanges)
actualRangeStr := actualRange.String()
if actualRangeStr != expectedRangeStr {
t.Errorf("Ranges \"%s\": expected compression to %s, actual %s\n", inputRangesStr, expectedRangeStr, actualRangeStr)
return
}
}
示例4: rateLimitStats
func rateLimitStats(resp *http.Response) {
if resp == nil {
return
}
curr := time.Seconds()
reset, _ := strconv.Atoi64(resp.GetHeader("X-RateLimit-Reset"))
remaining, _ := strconv.Atoi64(resp.GetHeader("X-RateLimit-Remaining"))
if remaining < 1 && reset-curr > 0 {
log.Printf("Twitter API limits exceeded. Sleeping for %d seconds.\n", reset-curr)
time.Sleep((reset - curr) * 1e9)
}
}
示例5: parseRange
// parseRange parses a Range header string as per RFC 2616.
func parseRange(s string, size int64) ([]httpRange, os.Error) {
if s == "" {
return nil, nil // header not present
}
const b = "bytes="
if !strings.HasPrefix(s, b) {
return nil, os.NewError("invalid range")
}
var ranges []httpRange
for _, ra := range strings.Split(s[len(b):], ",", -1) {
i := strings.Index(ra, "-")
if i < 0 {
return nil, os.NewError("invalid range")
}
start, end := ra[:i], ra[i+1:]
var r httpRange
if start == "" {
// If no start is specified, end specifies the
// range start relative to the end of the file.
i, err := strconv.Atoi64(end)
if err != nil {
return nil, os.NewError("invalid range")
}
if i > size {
i = size
}
r.start = size - i
r.length = size - r.start
} else {
i, err := strconv.Atoi64(start)
if err != nil || i > size || i < 0 {
return nil, os.NewError("invalid range")
}
r.start = i
if end == "" {
// If no end is specified, range extends to end of the file.
r.length = size - r.start
} else {
i, err := strconv.Atoi64(end)
if err != nil || r.start > i {
return nil, os.NewError("invalid range")
}
if i >= size {
i = size - 1
}
r.length = i - r.start + 1
}
}
ranges = append(ranges, r)
}
return ranges, nil
}
示例6: FileHandler
func FileHandler(store fs.LocalStore) http.HandlerFunc {
return func(resp http.ResponseWriter, req *http.Request) {
setBinaryResp(resp)
strong, hasStrong := mux.Vars(req)["strong"]
if !hasStrong {
writeResponseError(resp, http.StatusInternalServerError,
"Missing parameter: strong")
return
}
offsetStr, hasOffset := mux.Vars(req)["offset"]
if !hasOffset {
writeResponseError(resp, http.StatusInternalServerError,
"Missing parameter: offset")
return
}
offset, err := strconv.Atoi64(offsetStr)
if err != nil {
writeResponseError(resp, http.StatusInternalServerError,
fmt.Sprintf("Invalid format for length: %s", offsetStr))
return
}
lengthStr, hasLength := mux.Vars(req)["length"]
if !hasLength {
writeResponseError(resp, http.StatusInternalServerError,
"Missing parameter: length")
return
}
length, err := strconv.Atoi64(lengthStr)
if err != nil {
writeResponseError(resp, http.StatusInternalServerError,
fmt.Sprintf("Invalid format for length: %s", lengthStr))
return
}
buffer := bytes.NewBuffer([]byte{})
n, err := store.ReadInto(strong, offset, length, buffer)
if err != nil {
writeResponseError(resp, http.StatusInternalServerError, err.String())
return
}
if n < length {
writeResponseError(resp, http.StatusInternalServerError, io.ErrShortWrite.String())
}
resp.Write(buffer.Bytes())
}
}
示例7: PointFromString
func PointFromString(ptstr string) (*Point, os.Error) {
re := regexp.MustCompile("(-?[0-9]+),(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)")
matches := re.FindStringSubmatch(ptstr)
if len(matches) < 5 {
return nil, os.NewError("invalid pointstring")
}
x, ex := strconv.Atoi64(matches[1])
x2, ex2 := strconv.Atoi64(matches[2])
y, ey := strconv.Atoi64(matches[3])
y2, ey2 := strconv.Atoi64(matches[4])
if ex != nil || ex2 != nil || ey != nil || ey2 != nil {
return &Point{new(Integer), new(Integer)}, os.NewError("point.FromString: failed to parse coordinates.")
}
return &Point{&Integer{x, x2}, &Integer{y, y2}}, nil
}
示例8: verifyHmac
// verifyHmac verifies that a message authentication code (MAC) is valid.
//
// The provided source bytes must be in the form "value|timestamp|message".
func verifyHmac(h hash.Hash, key string, value []byte, timestamp, minAge,
maxAge int64) ([]byte, error) {
parts := bytes.SplitN(value, []byte("|"), 3)
if len(parts) != 3 {
return nil, ErrAuthentication
}
rv := parts[0]
tst, _ := strconv.Atoi64(string(parts[1]))
msg := parts[2]
if tst == 0 {
return nil, ErrBadTimestamp
}
if minAge != 0 && tst > timestamp-minAge {
return nil, ErrNewTimestamp
}
if maxAge != 0 && tst < timestamp-maxAge {
return nil, ErrOldTimestamp
}
// There are several other operations being done by the Encoder so not
// sure if ConstantTimeCompare() is worth at all.
msg2 := mac(h, key, rv, tst)
if len(msg) != len(msg2) || subtle.ConstantTimeCompare(msg, msg2) != 1 {
return nil, ErrAuthentication
}
return rv, nil
}
示例9: parseFieldParameters
// Given a tag string with the format specified in the package comment,
// parseFieldParameters will parse it into a fieldParameters structure,
// ignoring unknown parts of the string.
func parseFieldParameters(str string) (ret fieldParameters) {
for _, part := range strings.Split(str, ",", 0) {
switch {
case part == "optional":
ret.optional = true
case part == "explicit":
ret.explicit = true
if ret.tag == nil {
ret.tag = new(int)
*ret.tag = 0
}
case strings.HasPrefix(part, "default:"):
i, err := strconv.Atoi64(part[8:len(part)])
if err == nil {
ret.defaultValue = new(int64)
*ret.defaultValue = i
}
case strings.HasPrefix(part, "tag:"):
i, err := strconv.Atoi(part[4:len(part)])
if err == nil {
ret.tag = new(int)
*ret.tag = i
}
}
}
return
}
示例10: parseIndexLine
func parseIndexLine(l []byte) (*indexInfo, error) {
// fmt.Fprintf (os.Stderr, "Processing line:\n%s\n", l)
newIndexInfo := indexInfo{}
var err error
fields := bytes.Fields(l)
newIndexInfo.lemma = fields[LEMMA]
// newIndexInfo.pos, err = strconv.Atoui64(string(fields[POS]))
if len(fields[POS]) > 1 {
return nil, ERR_MSG(SYNTACTIC_CATEGORY_TOO_LONG)
}
newIndexInfo.pos = fields[POS][0]
ptr_cnt, err := strconv.Atoi(string(fields[PTR_CNT]))
if err != nil {
return nil, err
}
ptr_symbols := fields[SYMBOL : SYMBOL+ptr_cnt]
newIndexInfo.ptr_symbols = ptr_symbols
newIndexInfo.tagsense_cnt, err = strconv.Atoi(string(fields[TAGSENSE_CNT+ptr_cnt]))
if err != nil {
return nil, err
}
offsets_strs := fields[(SYNSET_OFFSET + ptr_cnt - 1):]
offsets := make([]int64, len(offsets_strs))
for i, offset := range offsets_strs {
offsets[i], err = strconv.Atoi64(string(offset))
if err != nil {
return nil, err
}
}
newIndexInfo.offsets = offsets
return &newIndexInfo, nil
}
示例11: ParseCase
func ParseCase(i int, line string) *Auction {
a := &Auction{Case: i}
tokens := strings.Fields(line)
for p, s := range tokens {
val, err := strconv.Atoi64(s)
if err != nil {
log.Panic(i, line, err)
}
switch p {
case 0:
a.N = val
case 1:
a.P1 = val
case 2:
a.W1 = val
case 3:
a.M = val
case 4:
a.K = val
case 5:
a.A = val
case 6:
a.B = val
case 7:
a.C = val
case 8:
a.D = val
}
}
if Debug {
log.Printf("%#v", *a)
}
return a
}
示例12: GetSecureCookie
func (ctx *Context) GetSecureCookie(name string) (string, bool) {
cookie, ok := ctx.Request.Cookies[name]
if !ok {
return "", false
}
parts := strings.Split(cookie, "|", 3)
val := parts[0]
timestamp := parts[1]
sig := parts[2]
if getCookieSig([]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
}
示例13: decodeSecureCookie
func decodeSecureCookie(value string) (user string, session string, err os.Error) {
parts := strings.Split(value, "|", 3)
if len(parts) != 3 {
err = os.NewError("Malformed cookie value")
return
}
val := parts[0]
timestamp := parts[1]
sig := parts[2]
// Check signature
if getCookieSig([]byte(val), timestamp) != sig {
return "", "", os.NewError("Signature error, cookie is invalid")
}
// Check time stamp
ts, _ := strconv.Atoi64(timestamp)
if ts+maxAge < time.UTC().Seconds() {
return "", "", os.NewError("Cookie is outdated")
}
buf := bytes.NewBufferString(val)
encoder := base64.NewDecoder(base64.StdEncoding, buf)
res, _ := ioutil.ReadAll(encoder)
str := string(res)
lst := strings.Split(str, "!", -1)
if len(lst) != 2 {
return "", "", os.NewError("Missing !")
}
return lst[0], lst[1], nil
}
示例14: parseIndexLine
func parseIndexLine(l []byte) *indexInfo {
// fmt.Fprintf (os.Stderr, "Processing line:\n%s\n", l)
newIndexInfo := indexInfo{}
var err os.Error
fields := bytes.Fields(l)
ptr_cnt, err := strconv.Atoi(string(fields[PTR_CNT]))
if err != nil {
fmt.Fprintf(os.Stderr, "I had a problem trying to convert '%s' to int\n", fields[PTR_CNT])
os.Exit(1)
}
newIndexInfo.lemma = fields[LEMMA]
// newIndexInfo.pos, err = strconv.Atoui64(string(fields[POS]))
if len(fields[POS]) > 1 {
fmt.Fprintf(os.Stderr, "POS has to be 1 letter code ('n', 'v', 'a' or 'r') and I have %s\n", fields[POS])
os.Exit(1)
}
newIndexInfo.pos = fields[POS][0]
newIndexInfo.tagsense_cnt, err = strconv.Atoi(string(fields[TAGSENSE_CNT+ptr_cnt]))
if err != nil {
fmt.Fprintf(os.Stderr, "I had a problem trying to convert %s to int32\n", fields[TAGSENSE_CNT+ptr_cnt])
os.Exit(1)
}
offsets_strs := fields[(SYNSET_OFFSET + ptr_cnt):]
offsets := make([]int64, len(offsets_strs))
for i, offset := range offsets_strs {
offsets[i], err = strconv.Atoi64(string(offset))
if err != nil {
fmt.Fprintf(os.Stderr, "I had a problem trying to convert the offset %s to int63\n", offset)
os.Exit(1) // log.Fatal?
}
}
newIndexInfo.offsets = offsets
return &newIndexInfo
}
示例15: FetchVia
func (c *Client) FetchVia(b *blobref.BlobRef, v []*blobref.BlobRef) (blobref.ReadSeekCloser, int64, os.Error) {
url := fmt.Sprintf("%s/camli/%s", c.server, b)
if len(v) > 0 {
buf := bytes.NewBufferString(url)
buf.WriteString("?via=")
for i, br := range v {
if i != 0 {
buf.WriteString(",")
}
buf.WriteString(br.String())
}
url = buf.String()
}
req := http.NewGetRequest(url)
if c.HasAuthCredentials() {
req.Header["Authorization"] = c.authHeader()
}
resp, err := req.Send()
if err != nil {
return nil, 0, err
}
var size int64
if s := resp.GetHeader("Content-Length"); s != "" {
size, _ = strconv.Atoi64(s)
}
return nopSeeker{resp.Body}, size, nil
}