/
core_type_uint64.go
67 lines (56 loc) · 1.37 KB
/
core_type_uint64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2014 The goyy Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package entity
import (
"strconv"
"gopkg.in/goyy/goyy.v0/util/errors"
"gopkg.in/goyy/goyy.v0/util/strings"
)
// Uint64 uint64 type.
type Uint64 struct {
base
value uint64
}
// Value gets the value.
func (me *Uint64) Value() uint64 {
return me.value
}
// ValuePtr gets the value of the pointer type.
func (me *Uint64) ValuePtr() *uint64 {
return &me.value
}
// SetValue sets the value.
func (me *Uint64) SetValue(v uint64) {
me.value = v
me.field.SetModified(true)
}
// SetDefault sets the default value.
func (me *Uint64) SetDefault(v string) error {
if strings.IsBlank(v) {
return errors.NewNotBlank("v")
}
val, err := strconv.ParseInt(v, 10, 64)
if err != nil {
logger.Error(err.Error())
return err
}
me.value = uint64(val)
return nil
}
// SetString sets the value of the string type.
func (me *Uint64) SetString(v string) error {
if err := me.SetDefault(v); err != nil {
return err
}
me.field.SetModified(true)
return nil
}
// String gets the value of the string type.
func (me *Uint64) String() string {
return strconv.Itoa(int(me.value))
}
// Name gets the name of the type.
func (me *Uint64) Name() string {
return "uint64"
}