Browse Source

Remove unnecessary type casts

Gunnar Þór Magnússon 1 year ago
parent
commit
0f91d69de4

+ 1
- 1
Makefile View File

@@ -19,7 +19,7 @@ debug:
19 19
 nocairo:
20 20
 	$(GO) build -ldflags '-X main.BuildVersion=$(VERSION)' $(PKG_CARBONAPI)
21 21
 
22
-carbonzipper:
22
+carbonzipper: $(shell find . -name '*.go' | grep -v 'vendor')
23 23
 	$(GO) build --ldflags '-X main.BuildVersion=$(VERSION)' $(PKG_CARBONZIPPER)
24 24
 
25 25
 test:

+ 8
- 8
date/date.go View File

@@ -50,27 +50,27 @@ func DateParamToEpoch(s string, qtz string, d int64, defaultTimeZone *time.Locat
50 50
 
51 51
 	if s == "" {
52 52
 		// return the default if nothing was passed
53
-		return int64(d)
53
+		return d
54 54
 	}
55 55
 
56 56
 	// relative timestamp
57 57
 	if s[0] == '-' {
58 58
 		offset, err := parser.IntervalString(s, -1)
59 59
 		if err != nil {
60
-			return int64(d)
60
+			return d
61 61
 		}
62 62
 
63
-		return int64(timeNow().Add(time.Duration(offset) * time.Second).Unix())
63
+		return timeNow().Add(time.Duration(offset) * time.Second).Unix()
64 64
 	}
65 65
 
66 66
 	switch s {
67 67
 	case "now":
68
-		return int64(timeNow().Unix())
68
+		return timeNow().Unix()
69 69
 	case "midnight", "noon", "teatime":
70 70
 		yy, mm, dd := timeNow().Date()
71 71
 		hh, min, _ := parseTime(s) // error ignored, we know it's valid
72 72
 		dt := time.Date(yy, mm, dd, hh, min, 0, 0, defaultTimeZone)
73
-		return int64(dt.Unix())
73
+		return dt.Unix()
74 74
 	}
75 75
 
76 76
 	sint, err := strconv.Atoi(s)
@@ -90,7 +90,7 @@ func DateParamToEpoch(s string, qtz string, d int64, defaultTimeZone *time.Locat
90 90
 	case len(split) == 2:
91 91
 		ts, ds = split[0], split[1]
92 92
 	case len(split) > 2:
93
-		return int64(d)
93
+		return d
94 94
 	}
95 95
 
96 96
 	var tz = defaultTimeZone
@@ -118,7 +118,7 @@ dateStringSwitch:
118 118
 			}
119 119
 		}
120 120
 
121
-		return int64(d)
121
+		return d
122 122
 	}
123 123
 
124 124
 	var hour, minute int
@@ -130,5 +130,5 @@ dateStringSwitch:
130 130
 	yy, mm, dd := t.Date()
131 131
 	t = time.Date(yy, mm, dd, hour, minute, 0, 0, defaultTimeZone)
132 132
 
133
-	return int64(t.Unix())
133
+	return t.Unix()
134 134
 }

+ 2
- 2
expr/functions/cairo/png/graphutil.go View File

@@ -79,7 +79,7 @@ func hexToRGBA(h string) (*color.RGBA, error) {
79 79
 	alpha := byte(255)
80 80
 
81 81
 	if len(h) == 6 {
82
-		if rgb, err := strconv.ParseUint(string(h), 16, 32); err == nil {
82
+		if rgb, err := strconv.ParseUint(h, 16, 32); err == nil {
83 83
 			r = uint8(rgb >> 16)
84 84
 			g = uint8(rgb >> 8)
85 85
 			b = uint8(rgb)
@@ -89,7 +89,7 @@ func hexToRGBA(h string) (*color.RGBA, error) {
89 89
 	}
90 90
 
91 91
 	if len(h) == 8 {
92
-		if rgb, err := strconv.ParseUint(string(h), 16, 32); err == nil {
92
+		if rgb, err := strconv.ParseUint(h, 16, 32); err == nil {
93 93
 			r = uint8(rgb >> 24)
94 94
 			g = uint8(rgb >> 16)
95 95
 			b = uint8(rgb >> 8)

+ 3
- 3
expr/functions/graphiteWeb/function.go View File

@@ -15,8 +15,8 @@ import (
15 15
 	"github.com/go-graphite/carbonapi/expr/interfaces"
16 16
 	"github.com/go-graphite/carbonapi/expr/metadata"
17 17
 	"github.com/go-graphite/carbonapi/expr/types"
18
-	"github.com/go-graphite/carbonapi/pkg/parser"
19 18
 	"github.com/go-graphite/carbonapi/limiter"
19
+	"github.com/go-graphite/carbonapi/pkg/parser"
20 20
 	pb "github.com/go-graphite/protocol/carbonapi_v3_pb"
21 21
 	"github.com/lomik/zapwriter"
22 22
 	"github.com/spf13/viper"
@@ -347,8 +347,8 @@ func (f *graphiteWeb) Do(e parser.Expr, from, until int64, values map[parser.Met
347 347
 		rewrite, _ := url.Parse(srv + "/render/")
348 348
 		v := url.Values{
349 349
 			"target": []string{target},
350
-			"from":   []string{strconv.FormatInt(int64(from), 10)},
351
-			"until":  []string{strconv.FormatInt(int64(until), 10)},
350
+			"from":   []string{strconv.FormatInt(from, 10)},
351
+			"until":  []string{strconv.FormatInt(until, 10)},
352 352
 			"format": []string{"json"},
353 353
 		}
354 354
 

+ 2
- 2
expr/helper/align.go View File

@@ -24,8 +24,8 @@ func AlignStartToInterval(start, stop, bucketSize int64) int64 {
24 24
 
25 25
 // AlignToBucketSize aligns start and stop of serie to specified bucket (step) size
26 26
 func AlignToBucketSize(start, stop, bucketSize int64) (int64, int64) {
27
-	start = int64(time.Unix(int64(start), 0).Truncate(time.Duration(bucketSize) * time.Second).Unix())
28
-	newStop := int64(time.Unix(int64(stop), 0).Truncate(time.Duration(bucketSize) * time.Second).Unix())
27
+	start = time.Unix(start, 0).Truncate(time.Duration(bucketSize) * time.Second).Unix()
28
+	newStop := time.Unix(stop, 0).Truncate(time.Duration(bucketSize) * time.Second).Unix()
29 29
 
30 30
 	// check if a partial bucket is needed
31 31
 	if stop != newStop {

+ 5
- 5
expr/types/types.go View File

@@ -59,7 +59,7 @@ func MarshalCSV(results []*MetricData) []byte {
59 59
 			b = append(b, r.Name...)
60 60
 			b = append(b, '"')
61 61
 			b = append(b, ',')
62
-			b = append(b, time.Unix(int64(t), 0).Format("2006-01-02 15:04:05")...)
62
+			b = append(b, time.Unix(t, 0).Format("2006-01-02 15:04:05")...)
63 63
 			b = append(b, ',')
64 64
 			if !math.IsNaN(v) {
65 65
 				b = strconv.AppendFloat(b, v, 'f', -1, 64)
@@ -139,7 +139,7 @@ func MarshalJSON(results []*MetricData) []byte {
139 139
 
140 140
 			b = append(b, ',')
141 141
 
142
-			b = strconv.AppendInt(b, int64(t), 10)
142
+			b = strconv.AppendInt(b, t, 10)
143 143
 
144 144
 			b = append(b, ']')
145 145
 
@@ -213,11 +213,11 @@ func MarshalRaw(results []*MetricData) []byte {
213 213
 		b = append(b, r.Name...)
214 214
 
215 215
 		b = append(b, ',')
216
-		b = strconv.AppendInt(b, int64(r.StartTime), 10)
216
+		b = strconv.AppendInt(b, r.StartTime, 10)
217 217
 		b = append(b, ',')
218
-		b = strconv.AppendInt(b, int64(r.StopTime), 10)
218
+		b = strconv.AppendInt(b, r.StopTime, 10)
219 219
 		b = append(b, ',')
220
-		b = strconv.AppendInt(b, int64(r.StepTime), 10)
220
+		b = strconv.AppendInt(b, r.StepTime, 10)
221 221
 		b = append(b, '|')
222 222
 
223 223
 		var comma bool

+ 6
- 6
intervalset/intervalset.go View File

@@ -48,12 +48,12 @@ func (i *IntervalSet) MarshalPickle() ([]byte, error) {
48 48
 	//   172: .    STOP
49 49
 	b := []byte("(cgraphite.intervals\nIntervalSet\no}(U\tintervals](cgraphite.intervals\nInterval\no}(U\x05startGA\xd3\xb3]\x8f\x99)\x02U\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18U\x03endGA\xd6\x0c\xdd\xe9\xe2\x9a\xe5U\x05tupleGA\xd3\xb3]\x8f\x99)\x02GA\xd6\x0c\xdd\xe9\xe2\x9a\xe5\x86ubaU\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18ub")
50 50
 
51
-	binary.BigEndian.PutUint64(b[89:97], uint64(math.Float64bits(float64(i.Start))))
52
-	binary.BigEndian.PutUint64(b[104:112], uint64(math.Float64bits(float64(i.End-i.Start))))
53
-	binary.BigEndian.PutUint64(b[118:126], uint64(math.Float64bits(float64(i.End))))
54
-	binary.BigEndian.PutUint64(b[134:142], uint64(math.Float64bits(float64(i.Start))))
55
-	binary.BigEndian.PutUint64(b[143:151], uint64(math.Float64bits(float64(i.End))))
56
-	binary.BigEndian.PutUint64(b[162:170], uint64(math.Float64bits(float64(i.End-i.Start))))
51
+	binary.BigEndian.PutUint64(b[89:97], math.Float64bits(float64(i.Start)))
52
+	binary.BigEndian.PutUint64(b[104:112], math.Float64bits(float64(i.End-i.Start)))
53
+	binary.BigEndian.PutUint64(b[118:126], math.Float64bits(float64(i.End)))
54
+	binary.BigEndian.PutUint64(b[134:142], math.Float64bits(float64(i.Start)))
55
+	binary.BigEndian.PutUint64(b[143:151], math.Float64bits(float64(i.End)))
56
+	binary.BigEndian.PutUint64(b[162:170], math.Float64bits(float64(i.End-i.Start)))
57 57
 
58 58
 	return b, nil
59 59
 }

+ 6
- 6
pkg/parser/parser.go View File

@@ -157,12 +157,12 @@ func (e *expr) Metrics() []MetricRequest {
157 157
 			var r2 []MetricRequest
158 158
 			for _, v := range r {
159 159
 				for i := int64(start); i < int64(end); i++ {
160
-					fromNew := int64(v.From) + i*int64(offs)
161
-					untilNew := int64(v.Until) + i*int64(offs)
160
+					fromNew := v.From + i*int64(offs)
161
+					untilNew := v.Until + i*int64(offs)
162 162
 					r2 = append(r2, MetricRequest{
163 163
 						Metric: v.Metric,
164
-						From:   int64(fromNew),
165
-						Until:  int64(untilNew),
164
+						From:   fromNew,
165
+						Until:  untilNew,
166 166
 					})
167 167
 				}
168 168
 			}
@@ -180,8 +180,8 @@ func (e *expr) Metrics() []MetricRequest {
180 180
 					return nil
181 181
 				}
182 182
 				for i := range r {
183
-					fromNew := int64(r[i].From) - int64(offs)
184
-					r[i].From = int64(fromNew)
183
+					fromNew := r[i].From - int64(offs)
184
+					r[i].From = fromNew
185 185
 				}
186 186
 			}
187 187
 		}

+ 2
- 2
tests/helper.go View File

@@ -281,10 +281,10 @@ func TestSummarizeEvalExpr(t *testing.T, tt *SummarizeEvalTestItem) {
281 281
 			t.Errorf("bad Step for %s:\ngot  %d\nwant %d", g[0].Name, g[0].StepTime, tt.Step)
282 282
 		}
283 283
 		if g[0].StartTime != tt.Start {
284
-			t.Errorf("bad Start for %s: got %s want %s", g[0].Name, time.Unix(int64(g[0].StartTime), 0).Format(time.StampNano), time.Unix(int64(tt.Start), 0).Format(time.StampNano))
284
+			t.Errorf("bad Start for %s: got %s want %s", g[0].Name, time.Unix(g[0].StartTime, 0).Format(time.StampNano), time.Unix(tt.Start, 0).Format(time.StampNano))
285 285
 		}
286 286
 		if g[0].StopTime != tt.Stop {
287
-			t.Errorf("bad Stop for %s: got %s want %s", g[0].Name, time.Unix(int64(g[0].StopTime), 0).Format(time.StampNano), time.Unix(int64(tt.Stop), 0).Format(time.StampNano))
287
+			t.Errorf("bad Stop for %s: got %s want %s", g[0].Name, time.Unix(g[0].StopTime, 0).Format(time.StampNano), time.Unix(tt.Stop, 0).Format(time.StampNano))
288 288
 		}
289 289
 
290 290
 		if !NearlyEqual(g[0].Values, tt.W) {

Loading…
Cancel
Save