Browse Source

调整目录结构

marion 5 years ago
parent
commit
7a67528b13
4 changed files with 2 additions and 88 deletions
  1. 2 1
      main.go
  2. 0 30
      utils/date/date.go
  3. 0 27
      utils/date/datetime.go
  4. 0 30
      utils/date/time.go

+ 2 - 1
main.go

@@ -33,7 +33,8 @@ func main() {
 	//for i := 0; i < numID*numGenerator; i++ {
 	//	id := <-consumer
 	//	if set.Contains(id) {
-	//		log.Fatal("duplicated id")
+	//		println("duplicated id")
+	//      return
 	//	} else {
 	//		set.Add(id)
 	//	}

+ 0 - 30
utils/date/date.go

@@ -5,7 +5,6 @@ import (
 	"encoding/binary"
 	"errors"
 	"fmt"
-	"github.com/vmihailenco/msgpack"
 	"strings"
 	"time"
 )
@@ -14,10 +13,6 @@ type Date time.Time
 
 const NormalDateFormat = "2006-01-02"
 
-func init() {
-	msgpack.RegisterExt(1, (*Date)(nil))
-}
-
 func (t Date) MarshalJSON() ([]byte, error) {
 	if y := t.Year(); y < 0 || y >= 10000 {
 		return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]")
@@ -63,31 +58,6 @@ func (t *Date) UnmarshalMsgpack(b []byte) error {
 	return nil
 }
 
-func DateRegisterExt() {
-	t := Date(time.Unix(123456789, 123))
-	b, err := msgpack.Marshal(&t)
-	if err != nil {
-		panic(err)
-	}
-
-	var v interface{}
-	err = msgpack.Unmarshal(b, &v)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(v.(*Date).UTC())
-
-	tm := &Date{}
-	err = msgpack.Unmarshal(b, tm)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(tm.UTC())
-
-	// Output: 1973-11-29 21:33:09.000000123 +0000 UTC
-	// 1973-11-29 21:33:09.000000123 +0000 UTC
-}
-
 func (t Date) MarshalText() ([]byte, error) {
 	if y := t.Year(); y < 0 || y >= 10000 {
 		return nil, errors.New("Time.MarshalText: year outside of range [0,9999]")

+ 0 - 27
utils/date/datetime.go

@@ -5,7 +5,6 @@ import (
 	"encoding/binary"
 	"errors"
 	"fmt"
-	"github.com/vmihailenco/msgpack"
 	"regexp"
 	"strings"
 	"time"
@@ -20,7 +19,6 @@ var (
 )
 
 func init() {
-	msgpack.RegisterExt(0, (*Datetime)(nil))
 	datePattern, _ = regexp.Compile(`([-:\s])(\d)([-:\s])`)
 }
 
@@ -69,31 +67,6 @@ func (t *Datetime) UnmarshalMsgpack(b []byte) error {
 	return nil
 }
 
-func DatetimeRegisterExt() {
-	t := Datetime(time.Unix(123456789, 123))
-	b, err := msgpack.Marshal(&t)
-	if err != nil {
-		panic(err)
-	}
-
-	var v interface{}
-	err = msgpack.Unmarshal(b, &v)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(v.(*Datetime).UTC())
-
-	tm := &Datetime{}
-	err = msgpack.Unmarshal(b, tm)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(tm.UTC())
-
-	// Output: 1973-11-29 21:33:09.000000123 +0000 UTC
-	// 1973-11-29 21:33:09.000000123 +0000 UTC
-}
-
 func (t Datetime) MarshalText() ([]byte, error) {
 	if y := t.Year(); y < 0 || y >= 10000 {
 		return nil, errors.New("Time.MarshalText: year outside of range [0,9999]")

+ 0 - 30
utils/date/time.go

@@ -5,7 +5,6 @@ import (
 	"encoding/binary"
 	"errors"
 	"fmt"
-	"github.com/vmihailenco/msgpack"
 	"strings"
 	"time"
 )
@@ -14,10 +13,6 @@ type Time time.Time
 
 const NormalTimeFormat = "15:04:05"
 
-func init() {
-	msgpack.RegisterExt(2, (*Time)(nil))
-}
-
 func (t Time) MarshalJSON() ([]byte, error) {
 	if y := t.Year(); y < 0 || y >= 10000 {
 		return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]")
@@ -63,31 +58,6 @@ func (t *Time) UnmarshalMsgpack(b []byte) error {
 	return nil
 }
 
-func TimeRegisterExt() {
-	t := Time(time.Unix(123456789, 123))
-	b, err := msgpack.Marshal(&t)
-	if err != nil {
-		panic(err)
-	}
-
-	var v interface{}
-	err = msgpack.Unmarshal(b, &v)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(v.(*Time).UTC())
-
-	tm := &Time{}
-	err = msgpack.Unmarshal(b, tm)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Println(tm.UTC())
-
-	// Output: 1973-11-29 21:33:09.000000123 +0000 UTC
-	// 1973-11-29 21:33:09.000000123 +0000 UTC
-}
-
 func (t Time) MarshalText() ([]byte, error) {
 	if y := t.Year(); y < 0 || y >= 10000 {
 		return nil, errors.New("Time.MarshalText: year outside of range [0,9999]")