util.go 614 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package cluster
  11. import (
  12. "fmt"
  13. "strconv"
  14. "devt.de/krotik/common/errorutil"
  15. )
  16. /*
  17. toUInt64 safely converts an interface{} to an uint64.
  18. */
  19. func toUInt64(v interface{}) uint64 {
  20. if vu, ok := v.(uint64); ok {
  21. return vu
  22. }
  23. cloc, err := strconv.ParseInt(fmt.Sprint(v), 10, 64)
  24. errorutil.AssertOk(err)
  25. return uint64(cloc)
  26. }