GOPATH\src\day\day.go
package day type Day uint const ( Sunday Day = iota Monday Tuseday Wednesday Thursday Friday Saturday ) func (day Day) String() string { switch day { case Sunday: return "Sunday" case Monday: return "Monday" case Tuseday: return "Tuesday" case Wednesday: return "Wednesday" case Friday: return "Friday" case Saturday: return "Saturday" default: return "Invalid" } }
main.go
package main import "fmt" import "day" func main() { var today day.Day today = day.Sunday tomorrow := day.Monday fmt.Println("today: ", today) fmt.Println("tomorrow: ", tomorrow) fmt.Printf("type of today: %T\n", today) fmt.Printf("type of tomorrow: %T\n", tomorrow) }
输出:
时间: 2024-10-10 06:04:16