| 1 |
|
| 2 |
-- go.mod -- |
| 3 |
module example.com |
| 4 |
go 1.18 |
| 5 |
|
| 6 |
-- template/template.go -- |
| 7 |
package template |
| 8 |
|
| 9 |
// Basic test of expression refactoring. |
| 10 |
// (Types are not important in this case; it could be done with gofmt -r.) |
| 11 |
|
| 12 |
import "time" |
| 13 |
|
| 14 |
func before(t time.Time) time.Duration { return time.Now().Sub(t) } |
| 15 |
func after(t time.Time) time.Duration { return time.Since(t) } |
| 16 |
|
| 17 |
-- in/b1/b1.go -- |
| 18 |
package b1 |
| 19 |
|
| 20 |
import "time" |
| 21 |
|
| 22 |
var startup = time.Now() |
| 23 |
|
| 24 |
func example() time.Duration { |
| 25 |
before := time.Now() |
| 26 |
time.Sleep(1) |
| 27 |
return time.Now().Sub(before) |
| 28 |
} |
| 29 |
|
| 30 |
func msSinceStartup() int64 { |
| 31 |
return int64(time.Now().Sub(startup) / time.Millisecond) |
| 32 |
} |
| 33 |
|
| 34 |
-- out/b1/b1.go -- |
| 35 |
package b1 |
| 36 |
|
| 37 |
import "time" |
| 38 |
|
| 39 |
var startup = time.Now() |
| 40 |
|
| 41 |
func example() time.Duration { |
| 42 |
before := time.Now() |
| 43 |
time.Sleep(1) |
| 44 |
return time.Since(before) |
| 45 |
} |
| 46 |
|
| 47 |
func msSinceStartup() int64 { |
| 48 |
return int64(time.Since(startup) / time.Millisecond) |
| 49 |
} |