Compare commits
12 Commits
1170be24c0
...
kd-live
| Author | SHA1 | Date | |
|---|---|---|---|
| c31f838ba8 | |||
| f9a146321c | |||
| ea8ae4d02c | |||
| 8173216e95 | |||
| ead6543d95 | |||
| dd05ebf6ce | |||
| 3024a17b54 | |||
| 65d3081870 | |||
| fcdf1642d2 | |||
| 262b9cadec | |||
| b61c5862cc | |||
| f385d6a7b8 |
59
coupon/helper.go
Normal file
59
coupon/helper.go
Normal file
@ -0,0 +1,59 @@
|
||||
package coupon
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"math/rand"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DisolveCouponCode(code string) (round string, key string) {
|
||||
var final []byte
|
||||
for _, n := range strings.Split(code, "-") {
|
||||
nb, err := hex.DecodeString(n)
|
||||
if err != nil {
|
||||
// 형식 오류
|
||||
return "", ""
|
||||
}
|
||||
final = append(final, nb...)
|
||||
}
|
||||
|
||||
if len(final) != 8 {
|
||||
// 형식 오류
|
||||
return "", ""
|
||||
}
|
||||
|
||||
uid := final[4:]
|
||||
left := binary.BigEndian.Uint16(uid[0:2])
|
||||
right := binary.BigEndian.Uint16(uid[2:4])
|
||||
|
||||
final = final[0:4]
|
||||
xor := binary.LittleEndian.Uint32(final)
|
||||
roundhashnum := xor ^ (uint32(left) * uint32(right))
|
||||
|
||||
roundhash := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(roundhash, roundhashnum)
|
||||
|
||||
round = hex.EncodeToString(roundhash)
|
||||
key = hex.EncodeToString(uid)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func MakeCouponRoundHash(name string) (hash string, roundNumber uint32) {
|
||||
m5 := md5.New()
|
||||
m5.Write([]byte(name))
|
||||
hashbt := m5.Sum(nil)
|
||||
|
||||
roundbt := make([]byte, 8)
|
||||
copy(roundbt, hashbt[:8])
|
||||
|
||||
roundseed := int64(binary.BigEndian.Uint64(roundbt))
|
||||
roundhash := make([]byte, 4)
|
||||
rand.New(rand.NewSource(roundseed)).Read(roundhash)
|
||||
roundNumber = binary.BigEndian.Uint32(roundhash)
|
||||
hash = hex.EncodeToString(roundhash)
|
||||
|
||||
return
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package flagx
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -125,9 +124,6 @@ func Duration(name string, value time.Duration, usage string) *time.Duration {
|
||||
return findProperFlagSet(name).Duration(name, value, usage)
|
||||
}
|
||||
|
||||
func TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string) {
|
||||
findProperFlagSet(name).TextVar(p, name, value, usage)
|
||||
}
|
||||
func Func(name, usage string, fn func(string) error) {
|
||||
findProperFlagSet(name).Func(name, usage, fn)
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module repositories.action2quare.com/ayo/gocommon
|
||||
|
||||
go 1.19
|
||||
go 1.18
|
||||
|
||||
replace repositories.action2quare.com/ayo/gocommon => ./
|
||||
|
||||
|
||||
@ -132,7 +132,8 @@ func (server *Server) shutdown() {
|
||||
logger.Println("http server shutdown. healthcheckcounter :", t)
|
||||
atomic.StoreInt64(&healthcheckcounter, math.MinInt64)
|
||||
|
||||
for cnt := 0; cnt < 100; {
|
||||
timer := 600 // 0.1 * 600 = 1분
|
||||
for cnt := 0; cnt < 100 && timer > 0; {
|
||||
next := atomic.LoadInt64(&healthcheckcounter)
|
||||
if next == t {
|
||||
cnt++
|
||||
@ -141,6 +142,7 @@ func (server *Server) shutdown() {
|
||||
cnt = 0
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
timer--
|
||||
}
|
||||
logger.Println("http server shutdown. healthcheck completed")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user