Skip to content

Commit

Permalink
Merge pull request #20 from istyle-inc/feature/organize_package_design
Browse files Browse the repository at this point in the history
パッケージ内の整理をした
  • Loading branch information
syossan27 committed May 2, 2018
2 parents e3d9c2c + 27e34e3 commit f924bff
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions app/iceflake.go
Expand Up @@ -28,8 +28,8 @@ type Option struct {
type IceFlake struct {
// Listener instance of net.Listener implementation
net.Listener
// iceflake.Generator Implant IDGenerator
iceflake.Generator
// iceflake.GeneratorService Implant IDGeneratorService
iceflake.GeneratorService
preparing chan interface{}
baseTime time.Time
option *Option
Expand All @@ -46,11 +46,11 @@ func New(o *Option) (*IceFlake, error) {
return nil, err
}
return &IceFlake{
Listener: l,
Generator: iceflake.New(o.WorkerID, o.BaseTime),
baseTime: o.BaseTime,
option: o,
preparing: make(chan interface{}),
Listener: l,
GeneratorService: iceflake.New(o.WorkerID, o.BaseTime),
baseTime: o.BaseTime,
option: o,
preparing: make(chan interface{}),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions app/iceflake_test.go
Expand Up @@ -45,7 +45,7 @@ func TestListen(t *testing.T) {
go ice.Listen(ctx)
<-ice.Preparing()

cli := ic.NewClient("unix", fp)
cli := ic.New("unix", fp)
result, err := cli.Get()
if err != nil {
t.Error("error: ", err)
Expand Down Expand Up @@ -75,7 +75,7 @@ func BenchmarkListen(b *testing.B) {
defer cancel()
go ice.Listen(ctx)
<-ice.Preparing()
cli := ic.NewClient("unix", fp)
cli := ic.New("unix", fp)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand Down
4 changes: 2 additions & 2 deletions client/iceflake/client.go
Expand Up @@ -14,8 +14,8 @@ type Client struct {
addr string
}

// NewClient returns new Client
func NewClient(listenType, addr string) *Client {
// New returns new Client
func New(listenType, addr string) *Client {
return &Client{
listenType: listenType,
addr: addr,
Expand Down
2 changes: 1 addition & 1 deletion client/iceflake/client_test.go
Expand Up @@ -45,7 +45,7 @@ func TestListen(t *testing.T) {
go ice.Listen(ctx)
<-ice.Preparing()

cli := NewClient("unix", fp)
cli := New("unix", fp)
result, err := cli.Get()
if err != nil {
t.Error("error: ", err)
Expand Down
16 changes: 8 additions & 8 deletions generator.go
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/istyle-inc/iceflake/foundation"
)

// Generator interface of generator generates each Unique ID
type Generator interface {
// GeneratorService interface of generator generates each Unique ID
type GeneratorService interface {
Generate() (uint64, error)
}

Expand All @@ -19,8 +19,8 @@ const (
initialSequentialNumber = 1
)

// GeneratorService local implement of Generator
type GeneratorService struct {
// Generator local implement of GeneratorService
type Generator struct {
w uint64
baseTime time.Time
lastTS uint64
Expand All @@ -29,8 +29,8 @@ type GeneratorService struct {
}

// New return new Generator instance
func New(workerID uint64, baseTime time.Time) Generator {
return &GeneratorService{
func New(workerID uint64, baseTime time.Time) GeneratorService {
return &Generator{
w: workerID,
baseTime: baseTime,
lastTS: 0,
Expand All @@ -39,7 +39,7 @@ func New(workerID uint64, baseTime time.Time) Generator {
}

// Generate generate unique id
func (g *GeneratorService) Generate() (uint64, error) {
func (g *Generator) Generate() (uint64, error) {
g.gate.Lock()
defer g.gate.Unlock()

Expand All @@ -57,6 +57,6 @@ func (g *GeneratorService) Generate() (uint64, error) {
}

// GetTimeInt get uint value differ between now and epochtime
func (g *GeneratorService) GetTimeInt() uint64 {
func (g *Generator) GetTimeInt() uint64 {
return uint64(foundation.InternalTimer.Now().Sub(g.baseTime).Round(time.Millisecond)) / uint64(time.Millisecond)
}
6 changes: 3 additions & 3 deletions generator_test.go
Expand Up @@ -70,7 +70,7 @@ func TestIceFlakeGenerator_Generate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := GeneratorService{
g := Generator{
w: tt.fields.w,
baseTime: tt.fields.baseTime,
lastTS: tt.fields.lastTS,
Expand All @@ -96,15 +96,15 @@ func TestNewIDGenerator(t *testing.T) {
tests := []struct {
name string
args args
want Generator
want GeneratorService
}{
{
name: "succeeded to make new generator",
args: args{
workerID: 1,
baseTime: time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC),
},
want: &GeneratorService{
want: &Generator{
w: 1,
baseTime: time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC),
lastTS: 0,
Expand Down

0 comments on commit f924bff

Please sign in to comment.