forked from lifei6671/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (44 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"flag"
"time"
"github.com/lifei6671/snowflake/server"
"strings"
"strconv"
)
func main() {
var port int
var workerIdBits int
var timeDate string
var sequenceBits int
var timestampBits int
var size int
var worker string
flag.IntVar(&port,"port",8181,"Snowflake Server listen port.")
flag.IntVar(&workerIdBits,"workerSize",10,"WorkerBits number.")
flag.StringVar(&worker,"worker","1","Worder id list.Please use , split.")
flag.StringVar(&timeDate,"time","2017-04-10","Snowflake start time.")
flag.IntVar(&sequenceBits,"sequenceSize",12,"SequenceBits sequence number.")
flag.IntVar(×tampBits,"timestampSize",41,"TimestampBits number.")
flag.IntVar(&size,"size",1000,"Buffer Size.")
flag.Parse()
ws := strings.Split(worker,",")
workers := make([]int64,len(ws))
for index, ws := range ws {
if r,err := strconv.ParseInt(ws,10,64);err == nil {
workers[index] = r
}
}
t,err := time.Parse("",timeDate)
if err != nil {
t = time.Now()
}
epochSeconds := t.Unix()
s,err := server.NewServer(port,size,workers,timestampBits,sequenceBits,workerIdBits,epochSeconds)
if err != nil {
fmt.Println(err)
}else{
s.Run()
}
}