fix: coding style and file format for chapter 10.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:28:43 +08:00
parent d9041c7fc3
commit ca79293078
19 changed files with 731 additions and 720 deletions

View File

@@ -1,40 +1,41 @@
// Output:
// Eastern Standard time
// Universal Greenwich time
// Central Standard time
package main
import "fmt"
type TZ int
const (
HOUR TZ = 60 * 60
UTC TZ = 0 * HOUR
EST TZ = -5 * HOUR
CST TZ = -6 * HOUR
)
var timeZones = map[TZ]string { UTC:"Universal Greenwich time",
EST:"Eastern Standard time",
CST:"Central Standard time" }
func (tz TZ) String() string { // Method on TZ (not ptr)
for name, zone := range timeZones {
if tz == name {
return zone
}
}
return ""
}
func main() {
fmt.Println(EST) // Print* knows about method String() of type TZ
fmt.Println(0 * HOUR)
fmt.Println(-6 * HOUR)
}
/* Output:
Eastern Standard time
Universal Greenwich time
Central Standard time
*/
// Output:
// Eastern Standard time
// Universal Greenwich time
// Central Standard time
package main
import "fmt"
type TZ int
const (
HOUR TZ = 60 * 60
UTC TZ = 0 * HOUR
EST TZ = -5 * HOUR
CST TZ = -6 * HOUR
)
var timeZones = map[TZ]string{UTC: "Universal Greenwich time",
EST: "Eastern Standard time",
CST: "Central Standard time"}
func (tz TZ) String() string { // Method on TZ (not ptr)
for name, zone := range timeZones {
if tz == name {
return zone
}
}
return ""
}
func main() {
fmt.Println(EST) // Print* knows about method String() of type TZ
fmt.Println(0 * HOUR)
fmt.Println(-6 * HOUR)
}
/* Output:
Eastern Standard time
Universal Greenwich time
Central Standard time
*/