Compare commits

12 Commits

4 changed files with 63 additions and 6 deletions

59
coupon/helper.go Normal file
View 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
}

View File

@ -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
View File

@ -1,6 +1,6 @@
module repositories.action2quare.com/ayo/gocommon
go 1.19
go 1.18
replace repositories.action2quare.com/ayo/gocommon => ./

View File

@ -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 {