Passed
Pull Request — master (#66)
by Hayrullah
56s
created

converter.go   A

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 31
dl 0
loc 111
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A gotil.ToFloat64 0 2 1
A gotil.ToInt8 0 2 1
A gotil.ToInt64 0 2 1
A gotil.ToInt32 0 2 1
A gotil.ToInt16 0 2 1
A gotil.ToFloat32 0 2 1
A gotil.ToInt 0 2 1
A gotil.ToUint 0 2 1
A gotil.Join 0 2 1
A gotil.ToString 0 2 1
A gotil.ToUint8 0 2 1
A gotil.ToUint32 0 2 1
A gotil.ToUint16 0 2 1
A gotil.ToUint64 0 2 1
1
package gotil
2
3
import (
4
	"github.com/gotilty/gotil/internal"
5
)
6
7
//ToFloat32 returns float32(0) with an error if the parameter is unsupported type.
8
//Just works with all primitive types.
9
func ToFloat32(a interface{}) (float32, error) {
10
	return internal.ToFloat32(a)
11
}
12
13
//ToFloat64 returns float64(0) with an error if the parameter is unsupported type.
14
//Just works with all primitive types.
15
func ToFloat64(a interface{}) (float64, error) {
16
	return internal.ToFloat64(a)
17
18
}
19
20
//ToInt returns int(0) with an error if the parameter is unsupported type.
21
//Just works with all primitive types.
22
func ToInt(a interface{}) (int, error) {
23
	return internal.ToInt(a)
24
25
}
26
27
//ToInt8 returns int8(0) with an error if the parameter is unsupported type.
28
//Just works with all primitive types.
29
func ToInt8(a interface{}) (int8, error) {
30
	return internal.ToInt8(a)
31
32
}
33
34
//ToInt16 returns int16(0) with an error if the parameter is unsupported type.
35
//Just works with all primitive types.
36
func ToInt16(a interface{}) (int16, error) {
37
	return internal.ToInt16(a)
38
39
}
40
41
//ToInt32 returns int32(0) with an error if the parameter is unsupported type.
42
//Just works with all primitive types.
43
func ToInt32(a interface{}) (int32, error) {
44
	return internal.ToInt32(a)
45
46
}
47
48
//ToInt64 returns int64(0) with an error if the parameter is unsupported type.
49
//Just works with all primitive types.
50
func ToInt64(a interface{}) (int64, error) {
51
	return internal.ToInt64(a)
52
53
}
54
55
//ToString returns empty string if the parameter is unsupported type.
56
//Just works with all primitive types, arrays and slices.
57
//alternative for slice and array gotil.Join(a, separator)
58
//Example1:
59
// 		ToString([]int{10,20,30}) returns "10,20,30"
60
//Example2:
61
//		data := []user{
62
// 		{
63
//			name: "Micheal",
64
//  		age:  27,
65
// 		},
66
// 		{
67
// 			name: "Joe",
68
// 			age:  30,
69
// 		 },
70
//		}
71
//		ToString(data)
72
//		// Output: "{Micheal 27},{Joe 30}"
73
func ToString(a interface{}) (string, error) {
74
	return internal.ToString(a)
75
76
}
77
78
//Join just works with array and slice
79
//Example1: Join([]int{10,20,30},"-") returns "10-20-30"
80
func Join(a interface{}, separator string) (string, error) {
81
	return internal.Join(a, separator)
82
}
83
84
//ToUint returns uint(0) with an error if the parameter is unsupported type.
85
//Just works with all primitive types.
86
func ToUint(a interface{}) (uint, error) {
87
	return internal.ToUint(a)
88
}
89
90
//ToUint8 returns uint8(0) with an error if the parameter is unsupported type.
91
//Just works with all primitive types.
92
func ToUint8(a interface{}) (uint8, error) {
93
	return internal.ToUint8(a)
94
}
95
96
//ToUint16 returns uint16(0) with an error if the parameter is unsupported type.
97
//Just works with all primitive types.
98
func ToUint16(a interface{}) (uint16, error) {
99
	return internal.ToUint16(a)
100
}
101
102
//ToUint32 returns uint32(0) with an error if the parameter is unsupported type.
103
//Just works with all primitive types.
104
func ToUint32(a interface{}) (uint32, error) {
105
	return internal.ToUint32(a)
106
}
107
108
//ToUint64 returns uint64(0) with an error if the parameter is unsupported type.
109
//Just works with all primitive types.
110
func ToUint64(a interface{}) (uint64, error) {
111
	return internal.ToUint64(a)
112
}
113