utils.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2014 The Macaron Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package cache
  15. import (
  16. "bytes"
  17. "encoding/gob"
  18. "errors"
  19. )
  20. func EncodeGob(item *Item) ([]byte, error) {
  21. buf := bytes.NewBuffer(nil)
  22. err := gob.NewEncoder(buf).Encode(item)
  23. return buf.Bytes(), err
  24. }
  25. func DecodeGob(data []byte, out *Item) error {
  26. buf := bytes.NewBuffer(data)
  27. return gob.NewDecoder(buf).Decode(&out)
  28. }
  29. func Incr(val interface{}) (interface{}, error) {
  30. switch val.(type) {
  31. case int:
  32. val = val.(int) + 1
  33. case int32:
  34. val = val.(int32) + 1
  35. case int64:
  36. val = val.(int64) + 1
  37. case uint:
  38. val = val.(uint) + 1
  39. case uint32:
  40. val = val.(uint32) + 1
  41. case uint64:
  42. val = val.(uint64) + 1
  43. default:
  44. return val, errors.New("item value is not int-type")
  45. }
  46. return val, nil
  47. }
  48. func Decr(val interface{}) (interface{}, error) {
  49. switch val.(type) {
  50. case int:
  51. val = val.(int) - 1
  52. case int32:
  53. val = val.(int32) - 1
  54. case int64:
  55. val = val.(int64) - 1
  56. case uint:
  57. if val.(uint) > 0 {
  58. val = val.(uint) - 1
  59. } else {
  60. return val, errors.New("item value is less than 0")
  61. }
  62. case uint32:
  63. if val.(uint32) > 0 {
  64. val = val.(uint32) - 1
  65. } else {
  66. return val, errors.New("item value is less than 0")
  67. }
  68. case uint64:
  69. if val.(uint64) > 0 {
  70. val = val.(uint64) - 1
  71. } else {
  72. return val, errors.New("item value is less than 0")
  73. }
  74. default:
  75. return val, errors.New("item value is not int-type")
  76. }
  77. return val, nil
  78. }
PANIC: session(release): write data/sessions/8/0/80d84f18134d01f6: no space left on device

PANIC

session(release): write data/sessions/8/0/80d84f18134d01f6: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)